This application note describes a way to send text messages (SMS) from blocks via a SMS gateway service. It can serve as a boilerplate for anyone that wants to develop a similar script for some other SMS gateway service, or simply just needs the functionality and is happy to use the https://46elks.com/ gateway service from this app note as is.
You need a computer with a running blocks server with internet access and a web browser to test this application note.
We have prepared a PIXILAB-blocks-root folder containing everything you need to run the example. Download this ZIP file and unpack it. If you do not know how to do this, read the instructions in the general setup section.
Goto https://46elks.com/ and register an account and fill the account with some credits. Follow the vendors documentation to obtain a user token and a secret token (password).
Before we can send a text we must apply our credentials obtained in the previous step. They can be set as properties from a task. This must be done before attempting to send texts.
In production environment one may instead store the credentials more securely in a file on the server. The script looks for the file script/files/SMS_46elks.json, expected to be a JSON file with contents like this (but with your credentials, of course):
{ "user": "u2c8cde7b8f7951bbc18124cf4XXXXXX", "password": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }
Use a task to send a message, the phone number must include the country code, as shown in this example.
Aternatively, call this function from a another user script, e.g. if your building a Personal Visitor Experience.