Twilio

Send SMS notifications.

Messaging and Conferencing · Twilio

Details

IDTwilio
ProviderTwilio
CategoryMessaging and Conferencing
From Version5.0.0
Supported ModulesAgentix XSIAM

README

TwilioSendSMS


send an SMS

Base Command

TwilioSendSMS

Input

Argument Name Description Required
to Phone number of SMS reciever (e.g. +123456789101). Required
body Message body. Required
from Phone number of SMS sender (e.g. +123456789101). Optional

Context Output

There is no context output for this command.

Configuration parameters

  • server — Server URL (e.g. https://192.168.0.1) (required)
  • sid — Account SID
  • token — Auth token
  • credentials_token — Account SID
  • from — Default sending number (e.g. +123456789101) (required)
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings

Commands (1)

  • TwilioSendSMS

    send an SMS

var sendRequest = function(method, url, body) {
    var account_sid = params.credentials_token ? params.credentials_token.identifier : params.sid;
    var auth_token = params.credentials_token ? params.credentials_token.password : params.token;

    if (!(account_sid && auth_token)){
        throw('Account SID and Auth token must be provided.');
    }
    var res = http(
        params.server.replace(/[\/]+$/, '')+'/'+account_sid+'/Messages.json',
        {
            Method: method,
            Body: body,
            Headers: {'Content-Type': ['application/x-www-form-urlencoded']},
            Username: account_sid,
            Password: auth_token
        },
        params.insecure,
        params.proxy
    );
    if (res.StatusCode < 200 || res.StatusCode >=300) {
        throw 'Request Failed.\nStatus code: ' + res.StatusCode + '.\nBody: ' + JSON.stringify(res.Body) + '.';
    }
    return res.Body;
};

var encodeToURLQuery = function(to, from, body){
    return "From="+encodeURIComponent('+'+from.replace(/^\+/, ''))+"&To="+encodeURIComponent('+'+to.replace(/^\+/, ''))+"&Body="+encodeURIComponent(args.body);
};

switch (command) {
    // This is the call made when pressing the integration test button.
    case 'test-module':
        // from Twilio instructions, in order to ger the list of accounts, the below curl command should be used.
        // using this as a method to test that the credentials and connectivity are good, without using sms buckets
        // curl -G https://api.twilio.com/2010-04-01/Accounts -u '[YOUR ACCOUNT SID]:[YOUR AUTH TOKEN]'
        sendRequest('GET', params.server.replace(/[\/]+$/, ''), "");
        return 'ok';
    default:
        sendRequest('POST', params.server.replace(/[\/]+$/, '')+'/'+params.sid+'/Messages.json', encodeToURLQuery(args.to, (args.from ? args.from : params.from), args.body));
        return 'Message sent successfully!';
}