Awaken Scripting User Guide

Please email helpdesk@awaken.io for omissions or errors.
×
Menu

Sending Messages with JavaScript

 
JavaScript can be used to send a message (either SMS or email) at any time in a Workflow, and can be a quick and easy way to send off messages without agent involvement.
 
It is also possible to make use of the Script.Email.Send() or Script.Sms.Send() functions to send just emails or SMS respectively.
 

How To

Inside any JavaScript-manipulating Field (Calculate, JavaScript, JavaScript - Button), use the function specified below.
 
Simple Syntax
The simple syntax requires a list of parameters:
Script.Message.Send(messageType, connectorType, connectorName, subject, recipients, from, body, defer, callback);
 
Name
Required / Optional
Explanation
messageType
Required
This is the message type that is being sent, either "sms" or "email".
connectorType
Required
This is the type of connector to be used, and must be set to a valid connector type such as "connector-sms-twilio" for this function. Connector types can be found in the Connectors module by selecting a connector and referring to the text in the top-right corner.
connectorName
Required
This is the Connector Name of the specified connector that you wish to use to send the message.
subject
Variable
This is the subject line of the generated message (availability is provider-specific). It is required when messageType is "email", but optional when the messageType is "sms".
recipients
Required
These are any recipients of the generated message, provided either as an array of strings, or as a comma- or semicolon-separated string.
from
Optional
This is the who the message will appear to be sent from (availability is provider-specific). If not provided, then any default specified in the Connector itself will be used.
body
Required
This is the body of the message.
defer
Optional
This is the time to defer sending of the message to, specified either as a JavaScript date object or a string in the format "YYYY-MM-DD hh:mm:ss". If not provided, then the message will be sent immediately.
callback
Optional
This allows the provision of a "callback" function which will be executed once the message scheduling attempt has returned, allowing you to react to either successful or failing message scheduling.
 
 
Example:
 
Script.Message.Send(
    "email",
    "connector-email-outbound",
    "Cirrus Example Connector",
    "Order Confirmation",
    ["a.bc@example.com", "d.ef@example.com"],
    "orders@example.com",
    "Thank you for ordering " + [Ordered Item],
    undefined,
    function(response) { if(response.Error != "") { Script.Toast.Error("Email Failure", response.Error); } }
);
 
 
Alternate Syntax
Since many of the arguments for the above syntax are optional, there is an alternate syntax where a JavaScript object is passed instead. This means that only the desired optional parameters need to be passed:
 
Script.Message.Send({
    messageType: "sms",
    connectorType: "connector-sms-twilio",
    connectorName: "Twilio SMS Example Connector",
    recipients: "+10987654321",
    from: "+441234098765",
    body: "We've raised your issue with an engineer, and your Job ID is " + [var_csSessionID],
    callback: function(response) { if(response.Error != "") { Script.Toast.Error("SMS Failure", response.Error); } }
});
 
 
Any optional parameters that are omitted will use their default value, as stated in the above table. As this is a JavaScript object, the order in which the parameters are listed in this alternate syntax doesn't matter, as long as the key:value pairs are preserved.
 
 

Notes

As multiple duplicate messages can be queued, it is advised that caution is used if this function is invoked in a Calculate Field, due to the way that Calculate Fields will run every time an action is taken or Field's value is altered.