Creating SMS Templates and Sending SMS


Openscreen SDK allows you to Integrate SMS capabilities into your contactless applications! You can send SMS messages to Contacts within your project using pre-defined SMS templates (recommended) or by simply adding the message in the body parameter.

Requirements

Creating SMS Templates

SMS Templates are simply pre-defined strings of messages to be used while sending SMS. A unique feature of SMS templates is that they allow you to embed Asset attributes in the message. The embedded attributes are rendered during the call to send SMS which contains the necessary Asset information.

Use the following code to store an SMS template in an Openscreen project:

1 2 3 4 5 6 7 8 9 10 11 12 //Obtain the projectId from the Openscreen Dashboard const projectId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; async function main(){ const smsTemplate = await os.project(projectId).smsTemplates().create({ body: "SMS Template Text body", smsTemplateName: "firstTemplate", responseUrl: "httpe://myapp/sms-response", statusUrl: "httpe://myapp/sms-status", }); }
1 2 3 4 5 6 7 8 9 #Obtain your project_id from the Openscreen Dashboard project_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' sms_template = os.project(project_id).sms_templates().create({ "body": "Body of the message for {{asset.name}}", "sms_template_name": "firstTemplate", "response_url": "https://myapp/sms-response", "status_url": "https://myapp/sms-status" })

Sending SMS

In order to send SMS to an Openscreen Contact, you will need a unique scanId.

Note: As the application developer, it is your responsibility to ensure a valid Consent is captured before sending SMS. Openscreen calls to send SMS will fail if a Contact does not have a valid Consent object.

Use the code below to send SMS to a Contact:

1 2 3 4 5 6 7 8 9 10 11 // Obtain the scanId and paste below const scanId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; const contactId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; async function main(){ const sms = await os.scan(scanId).sms().send({ smsTemplateName: "firstTemplate", contactId, }) }
1 2 3 4 5 6 7 scan_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' contact_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' sms = ospro.scan(scan_id).sms().send({ "sms_template_name": first_template, "contact_id": contact_id })

Next Steps

You are now ready to build your own custom applications using Openscreen SDKs! Check out all the endpoints under the Core Objects section for further information.

Openscreen also provides end-to-end QR Code solutions tailored to your needs. Contact us to learn about the endless possibilities!