Last active
August 29, 2015 14:05
-
-
Save torpio/ed7bee00aac92d81c371 to your computer and use it in GitHub Desktop.
Takes a webhook from FLG 360 and adds a task to the lead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This script receives a webhook from FLG 360 and creates a task. You can choose the description of the task, its due date/time and the user it should be assigned to. | |
You can use curly bracket templating to insert any {{value}} from the FLG 360 webhook, for example {{data1}}. | |
*/ | |
var settings = {}; | |
// The description of the task. | |
settings.DESCRIPTION = '' | |
// The due date/time. | |
settings.DUE_DATE_AND_TIME = '{{received}}' | |
// The full name of the user that the task should be assigned to (case sensitive, exactly as shown in FLG 360). | |
// Leave BLANK to assign the task to the lead's assigned user. | |
settings.user = '' | |
if (!settings.DESCRIPTION) { | |
log.error("Please provide the description for the task in settings."); | |
} else if (!settings.DUE_DATE_AND_TIME) { | |
log.error("Please specify a due date/time for the task in settings."); | |
} else { | |
// Substitute any placeholders | |
var dueDateTime = helper.template(settings.DUE_DATE_AND_TIME || "", request.body); | |
var description = helper.template(settings.DESCRIPTION || "", request.body); | |
var user = helper.template(settings.user || "", request.body); | |
// Build the task create in FLG 360 | |
var input = "<data> \ | |
<request>create</request> \ | |
<type>Task</type> \ | |
<leadid>" + request.body.id + "</leadid> \ | |
<duedatetime>" + dueDateTime + "</duedatetime> \ | |
<field1>" + XML.safe(description) + "</field1> \ | |
<user>" + XML.safe(user ? user : request.body.username) + "</user> \ | |
</data>"; | |
// Create the task | |
service.post('flg360', 'APIActivity.php', input, function (error, status, result) { | |
if (error) { | |
log.error("Couldn't create the task.", input, error); | |
} else if (status >= 500 || result.indexOf('<code>0</code>') === -1) { | |
log.error("Couldn't create the task.", input, result); | |
} else { | |
log.info("Successfully created the task.", result); | |
} | |
}); | |
} | |
// Install with #torpio at https://torpio.com/app/scripts/shared/view/34021 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment