SMS SUBSCRIPTION
How to build a subscription service with Alerting Hub
How to build a subscription service with Alerting Hub
A subscription service enables interested parties to add themselves to a specific list to receive future notifications. It also presents a means for them to be easily removed should they no longer wish to be contacted. It allows you to build lists of clients or contacts that you can then notify as a group should predetermined events occur; some examples would include:
From a customer convenience perspective, SMS subscription is a quick and hassle-free way to sign up to notifications by simply texting a keyword to the service they wish to subscribe to. Using the Alerting Hub API, enabling SMS based subscription is straightforward for the developer.
In this example we’ll show the steps needed to use Alerting Hub to assist you in creating an SMS subscription service that allows you to have the final say on who does / doesn’t make the list. This gives you more control over your own services, allows you to integrate with any existing technology and ensures that your own subscription and client lists stay synchronized with Alerting Hub’s.
Subscription lists are managed in Alerting Hub using the contact group capability. To save an initial empty contact group send the following to our /storecontent API call:
{ "version": "latest", "apiKey": "xxxxxx-xxxx-xxxxxx-xxxx", "content": [ { "contentType": "contactGroup", "tag": "aTag", "content": { "contacts": [] }, "contentEncoding": "json", "storeDetails": { "storeName": "MySubscriptionGroup" } } ] }
The above JSON simply specifies an empty contact group (contacts set is empty) and that can be referred to as ‘MySubscriptionGroup’. More details on the /storecontent API call can be found here and more details on contact groups can be found here.
If you had a pre-existing set of contacts / clients you wanted adding to the contact group then you can simply add them all in one go by populating the contacts array as required.
On a successful API call you will receive back some JSON that will look similar to this:
{ "success": true, "returnCode": 200, "content": [ { "contentType": "contactGroup", "tag": " aTag ", "success": true, "storeId": "xxxxxx-xxxx-xxxxxx-xxxx", "storeName": "MySubscriptionGroup" } ] }
The important information is the success = true element, you can ignore the storeId if you want as you can always refer to your saved contact group by the name you gave it ‘MySubscriptionGroup’.
We now have registered keywords and we have a basic subscription list stored away. The next step is to ensure you can receive events when Alerting Hub receives SMS to it inboxes that contain your keywords.
There are two ways to do this, either by Alerting Hub calling you back on a webhook (see here) when the event occurs or by you regularly polling Alerting Hub for events using the /collectevents API (see here).
You will most likely have already done this step when you initially setup your Alerting Hub API account and began using it so this is presented here for completeness only.
When you receive events from Alerting Hub relating to your keywords you will receive something that looks similar to this:
{ "alerter": "+441000100010", "keyword": "subscribe", "event": "keyword", "type": "sms", "alertees": [ "+441234512345" ], "whence": "2021-12-08T08:09:39.000Z", "reply": "subscribe John Smith", "replyEncoding": "utf8" }
As you can see, the important items are:
When you receive a notification of a keyword event, as described above, or if you have other mechanisms for allowing subscribing / unsubscribing (e.g. via a web portal, or an automatic unsubscribe after a certain period) then your next step is to update the contact list as held by Alerting Hub (assuming that you are happy to add the person requesting the subscription).
If you wanted to add a person to the list you would do so using the same /storecontent API call as shown in step 2 except this time you would send something similar to:
{ "version": "latest", "apiKey": " xxxxxx-xxxx-xxxxxx-xxxx ", "content": [ { "contentType": "contactGroup", "tag": "aTag", "content": { "contacts": [ { "id": "+441234512345", "sms": "+441234512345" } ] }, "contentEncoding": "json", "options": { "contactGroupSpecific": { "partialUpdate": true } }, "storeDetails": { "storeName": "MySubscriptionGroup" } } ] }
As you will see the above is very close to the original /storecontent only this time we are:
You will notice that the contact consists of two items, an id and an sms entry. The former (id) must be specified and is a unique reference for the contact, in this case it’s easy enough to just use the phone number; the latter (sms) specifies the phone number to use to send the contact an SMS.
If you have a pre-existing database of potential clients you could set the id to be their unique database reference, client number or full name.
If you wanted to remove someone from the contact list (unsubscribe) then you make a similar call to /storecontent but in this case it would look something like:
{ "version": "latest", "apiKey": "xxxxxx-xxxx-xxxxxx-xxxx", "content": [ { "contentType": "contactGroup", "tag": "aTag", "content": { "deletions": { "contacts": [ { "id": "+441234512345" } ] } }, "contentEncoding": "json", "options": { "contactGroupSpecific": { "partialUpdate": true } }, "storeDetails": { "storeName": "MySubscriptionGroup" } } ] }
As you can see, the only difference is that the original ‘contacts’ has been removed and replaced with a ‘deletions|contacts’ section that contains just the ids of the contacts requiring removal.
All of the above steps are related to setting up and maintaining the subscription list (contact group) but how do you actually use that to reach people via Alerting Hub? You can specify that subscription list when you make a call to Alerting Hub’s /sendalert API call (see here). To send an SMS to everyone in the MySubscriptionGroup contact group you would call /sendalert with something like the following:
{ "version": "latest", "apiKey": "xxxxxx-xxxx-xxxxxx-xxxx", "clientRef": "myClientRef", "contactGroup": { "storedContactGroup": { "storeName": "MySubscriptionGroup" } }, "alert": [ { "alertType": "sms", "tag": "t1", "content": "Hello to all members of the group", "contentEncoding": "utf8", "sender": "ACME Inc", "contactSetList": "all" } ] }
That’s it, everyone in the subscription list will receive that SMS message. You will see how we specify the saved subscription list in the storedContactGroup element and we can tell Alerting Hub to send to everyone using the special contact set of ‘all’ in the ‘contactSetList’ section.
The following notes may be of interest:
This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.
OKLearn moreWe may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.
Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.
These cookies are strictly necessary to provide you with services available through our website and to use some of its features.
Because these cookies are strictly necessary to deliver the website, refuseing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.
We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.
We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.
These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.
If you do not want that we track your visit to our site you can disable tracking in your browser here:
We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.
Google Webfont Settings:
Google Map Settings:
Google reCaptcha Settings:
Vimeo and Youtube video embeds:
The following cookies are also needed - You can choose if you want to allow them:
You can read about our cookies and privacy settings in detail on our Privacy Policy Page.
Privacy policy