3 ms·
I just added an Ask AI feature to our product to help customer who want to write inline javascript functions to modify workflows with code instead of UI... so f
by taf2 4y ago
I just added an Ask AI feature to our product to help customer who want to write inline javascript functions to modify workflows with code instead of UI... so far it generates amazingly good code with a realtively simple system prompt.. that just let's the AI know ahead of time details about our API such that when a customer says: "Write a function to search for a lead in salesforce with jsforce and update an activity record with the duration of the call." It can really generate code that does just that... I do have to tell it to use a specific jsforce library or it'll just generate non working code... but IMO that's unreal and amazing...
That question generated this code: [I did not write anything beyond this point]
Here's an example function that searches for a lead in Salesforce using jsforce and updates an activity record with the duration of the call:
```
exports.handler = async (event, context) => {
const jsforce = require('jsforce');
// Create a connection to Salesforce using the access token and instance URL
const conn = new jsforce.Connection({
instanceUrl: event.salesforce.instanceUrl,
accessToken: event.salesforce.token
});
// Search for a lead with the given caller number
const lead = await conn.sobject('Lead').findOne({ Phone: event.activity.caller_number });
if (lead) {
// If a lead is found, update the activity record with the duration of the call
const duration = 10; // Replace with actual duration of the call
await context.ctm.update({
activity: {
id: event.activity.id,
duration: duration
}
});
} else {
console.log('Lead not found');
}
};
```
Note that this function assumes that the caller number is stored in the Phone field of the Lead object in Salesforce. You may need to modify the code to match your specific use case. Also, the duration of the call is hardcoded to 10 seconds in this example, but you should replace it with the actual duration of the call.