/sendalert code snippets

To aid your development, we have created a number of code snippets that you can use as reference material or as the basis for your application requirements.

Alert type – email

{
    "version": "latest",
    "apiKey": "abcdefghijklmnopqrstuvwxyz",
    "clientRef": "abcd-efgh",
    "options": {
        "notification": "poll",
        "notificationType": "json"
    },
    "alert": [
        {
            "alertType": "email",
            "tag": "t1",
            "to": "All staff",
            "sender": "ACME Trading",
            "replyTo": "ACME Trading",
            "subject": "This is an email subject",
            "recipientList": "somebody@somewhere.com, someoneelse@somewhere.com",
            "content": "This is an email body\n",
            "contentEncoding": "utf8",
            "emailBodyIsMultipart": false
        }
    ]
}

Alert type – voice

{
    "version": "latest",
    "apiKey": "abcdefghijklmnopqrstuvwxyz",
    "clientRef": "abcd-efgh",
    "alert": [
        {
            "alertType": "call",
            "sender": "+447777100100",
            "recipients": [
                "+447777100100",
                "+447777100101", 
                "+447777100102"
            ],
            "tag": "t1",
            "voiceFormat": "mp3",
            "contentEncoding": "base64",
            "content": "UklGRgi3AA................=="
        }
    ]
}

Schedule SMS

{
    "version": "latest",
    "apiKey": "abcdefghijklmnopqrstuvwxyz",
    "clientRef": "abcd-efgh",
    "options": {
        "notification": "poll",
        "notificationType": "json",
        "schedule": {
            "start": "now",
            "delay": "5m"
        }
    },
    "alert": [
        {
            "alertType": "sms",
            "tag": "t1",
            "content": "This is an SMS",
            "contentEncoding": "utf8",
            "sender": "+447777100100",
            "recipientList": "+447777100100,+447777100101,+447777100102"
        }
    ]
}

Voice alert using stored content

{
    "version": "latest",
    "apiKey": "abcdefghijklmnopqrstuvwxyz",
    "clientRef": "abcd-efgh",
    "options": {
        "notification": "poll",
        "notificationType": "json"
    },
    "alert": [
        {
            "alertType": "call",
            "tag": "t1",
            "storedContent": "e42b1fd0-70fc-4697-b646-9f0fab7306d0",
            "sender": "+447777100100",
            "recipientList": "+447777100100"
        }
    ]
}

Voice alert using TTS with retries

{
    "version": "latest",
    "apiKey": "abcdefghijklmnopqrstuvwxyz",
    "clientRef": "abcd-efgh",
    "alert": [
        {
            "alertType": "call",
            "sender": "+447777100100",
            "recipientList": "+447777100100",
            "tag": "t1",
            "voiceFormat": "tts",
            "content": "Hello, this is a test announcement. Please press any key and then hangup. Thank you.",
            "contentEncoding": "utf8",
            "ivrControl": 
                "ivrRequireResponse": true,
                "ivrAttempts" : 3
            }
        }
    ]
}

Combined SMS & voice alert

{
    "version": "latest",
    "apiKey": "abcdefghijklmnopqrstuvwxyz",
    "clientRef": "abcd-efgh",
    "alert": [
        {
            "alertType": "sms",
            "tag": "t1",
            "content": "This is an SMS 1",
            "contentEncoding": "utf8",
            "sender": "+447777100100",
            "recipientList": "+447777100100"
        },
        {
            "alertType": "call",
            "sender": "+447777100100",
            "recipients": [
                "+447777100100",
                "+447777100100",
                "+447777100100"
            ],
            "tag": "t1",
            "voiceFormat": "mp3",
            "contentEncoding": "base64",
            "content": "UklGRgi3.................w=="
        }
    ]
}

Snow alert

{
  "version" : "latest",
  "apiKey" : "abcdefghijklmnopqrstuvwxyz", 
  "clientRef" : "LondonSnow",
  "options": {
    "notification" : "poll",
    "notificationType" : "json"
  }
  "alert" : [ 
    {
        "alertType" : "sms",
        "tag" : "LondonSnowSMSTag",
        "recipientList" : "+447777100100,+447777100101,+447777100102",
        "content" : "Due to snow the school will be closed today",
        "contentEncoding" : "utf8"
        "sender" : "SNOW ALERT"
    }
  ]
}

SMS with lookups

{
  "version" : "latest",
  "apiKey" : "abcdefghijklmnopqrstuvwxyz", 
  "clientRef" : "my-reference",
  "options": {
    "notification" : "poll",
    "notificationType" : "json"
  }
  "alert" : [ 
    {
        "alertType" : "sms",
        "tag" : "tag1",
        "recipientList" : "+447777100100,+447777100101,+447777100102",
        "content" : "This is message for {recipient} on {datetime-DD/MM/YYYY}. Click {shortlink} to let us know you've seen this.",
        "contentEncoding" : "utf8",
        "sender" : "My Company",
        "lookups": { 
            "performLookups": true, 
            "uniqueLookups": true, 
            "shortlink": { 
                "reference": "a-reference", 
                "url": "https://my-companies-url.com/alertinghub-click-through"
            }
        }
    }
  ]
}

SMS with contact group and lookups

{
  "version" : "latest",
  "apiKey" : "abcdefghijklmnopqrstuvwxyz", 
  "clientRef" : "my-reference",
  "options": {
    "notification" : "poll",
    "notificationType" : "json"
  },
  "contactGroup" : {
    "inlineContactGroup" : {
      "name": "test",
      "contacts": [
        {
          "id": "name-0",
          "sms": "+447976100000",
          "email": "email-0@mycompany.com",
          "call": "+447976200000",
          "lookups": {
            "firstname": "fname-0",
            "lastname": "sname-0"
          }
        },
        {
          "id": "name-1",
          "sms": "+447976100001",
          "email": "email-1@mycompany.com",
          "call": "+447976200001",
          "lookups": {
            "firstname": "fname-1",
            "lastname": "sname-1"
          }
        },
        {
          "id": "name-2",
          "sms": "+447976100002",
          "email": "email-2@mycompany.com",
          "call": "+447976200002",
          "lookups": {
            "firstname": "fname-2",
            "lastname": "sname-2"
          }
        },
        {
          "id": "name-3",
          "sms": "+447976100003",
          "email": "email-3@mycompany.com",
          "call": "+447976200003",
          "lookups": {
            "firstname": "fname-3",
            "lastname": "sname-3"
           }
        }
      ],
      "sets": [
        {
          "name": "sales",
          "ids": [ "name-0", "name-2" ]
        },
        {
          "name": "management",
          "ids": [ "name-1", "name-3" ]
        }
      ]
    }
  },
  "alert" : [ 
    {
        "alertType" : "sms",
        "tag" : "tag1",
        "contactSets" : [ "sales" ],
        "content" : "This is a sales team message for {firstname} {lastname} on {datetime-DD/MM/YYYY}. Click {shortlink} to let us know you've seen this.",
        "contentEncoding" : "utf8",
        "sender" : "My Company",
        "lookups": { 
            "performLookups": true, 
            "uniqueLookups": true, 
            "shortlink": { 
                "reference": "a-reference", 
                "url": "https://my-companies-url.com/alertinghub-click-through"
            }
        }
    },
    {
        "alertType" : "sms",
        "tag" : "tag1",
        "contactSets" : [ "all" ],
        "content" : "This is a company wide message for {firstname} {lastname} on {datetime-DD/MM/YYYY}. Click {shortlink} to let us know you've seen this.",
        "contentEncoding" : "utf8",
        "sender" : "My Company",
        "lookups": { 
            "performLookups": true, 
            "uniqueLookups": true, 
            "shortlink": { 
                "reference": "a-reference", 
                "url": "https://my-companies-url.com/alertinghub-click-through"
            }
        }
     }
  ]
}

SMS and TTS voice with saved contact group and lookups

{
  "version" : "latest",
  "apiKey" : "abcdefghijklmnopqrstuvwxyz", 
  "clientRef" : "my-reference",
  "options": {
    "notification" : "poll",
    "notificationType" : "json"
  },
  "contactGroup" : {
    "storedContactGroup" : "e42b1fd0-70fc-4697-b646-9f0fab7306d0"
  },
  "alert" : [ 
    {
        "alertType" : "sms",
        "tag" : "tag1",
        "contactSets" : [ "all" ],
        "content" : "A message for {firstname} {lastname}. Click {shortlink} to let us know you've seen this.",
        "contentEncoding" : "utf8",
        "sender" : "My Company",
        "lookups": { 
            "performLookups": true, 
            "uniqueLookups": true, 
            "shortlink": { 
                "reference": "a-reference", 
                "url": "https://my-companies-url.com/alertinghub-click-through"
            }
        }
    },
    {
        "alertType": "call",
        "sender": "+447777100100",
        "contactSets" : [ "management" ],
        "tag": "t1",
        "voiceFormat": "tts",
        "content": "Hello, this is a message for {firstname} {lastname}. Please press any key and then hangup. Thank you.",
        "contentEncoding": "utf8",
        "ivrControl": 
            "ivrRequireResponse": true,
            "ivrAttempts" : 3
        },
        "lookups": { 
            "performLookups": true, 
            "uniqueLookups": true
        }
    }
  ]
}

Escalation – SMS/Email to voice

Overview

This example shows two linked-alerts, the 1st uses a stored contact group to send to a number of SMS and emails (in fact using a contact-set), the 2nd, scheduled for 1 hour later then calls any of the original contact-set who did not respond to the SMS or email (either via a direct reply or by the clicking on the embedded shortlink). Note that this example would be a perfect fit for using the /sendalerts API wherein both the 1st and 2nd alert could be specified in a single API call.

1st alert

{
  "version" : "latest",
  "apiKey" : "abcdefghijklmnopqrstuvwxyz", 
  "clientRef" : "my-reference",
  "contactGroup" : {
    "storedContactGroup" : "e42b1fd0-70fc-4697-b646-9f0fab7306d0"
  },
  "linkedAlerts": {
    "linkRef": "sms-then-call"
  },
  "alert" : [ 
    {
        "alertType" : "sms",
        "tag" : "tag1",
        "contactSets" : [ "all" ],
        "content" : "A message for {firstname} {lastname}. Click {shortlink} to let us know you've seen this.",
        "contentEncoding" : "utf8",
        "sender" : "My Company",
        "lookups": { 
            "performLookups": true, 
            "shortlink": { 
                "reference": "a-reference", 
                "url": "https://my-companies-url.com/alertinghub-click-through"
            }
        }
    },
    {
       "alertType": "email",
       "tag": "t2",
       "to": "All staff",
       "sender": "ACME Trading",
       "replyTo": "ACME Trading",
       "subject": "Important message",
       "contactSets" : [ "all" ],
       "content": "An email for {firstname} {lastname}. Click {shortlink} to let us know you've seen this.\n",
       "contentEncoding": "utf8",
       "lookups": { 
            "performLookups": true, 
            "shortlink": { 
                "reference": "a-reference", 
                "url": "https://my-companies-url.com/alertinghub-click-through"
            }
        }
     }
  ]
}

2nd alert

{
  "version" : "latest",
  "apiKey" : "abcdefghijklmnopqrstuvwxyz", 
  "clientRef" : "my-reference",
  "linkedAlerts": {
    "linkRef": "sms-then-call"
  },
  "alert" : [ 
    {
        "alertType": "call",
        "sender": "+447777100100",
        "options": {
          "schedule": {
            "start": "now",
            "delay": "1h"
          }
        },
        "linkedAlertModifiers": {
          "except": {
            "previouslySeen": "sms,email,shortlink"
          }
        },
        "contactSets" : [ "all" ],
        "tag": "t1",
        "voiceFormat": "tts",
        "content": "Hello, this is a message for {firstname} {lastname}. Please press any key and then hangup. Thank you.",
        "contentEncoding": "utf8",
        "ivrControl": 
            "ivrRequireResponse": true,
            "ivrAttempts" : 3
        },
        "lookups": { 
            "performLookups": true, 
            "uniqueLookups": true
        }
    }
  ]
}