Skip to content

Instantly share code, notes, and snippets.

@birinder-lobana
Last active December 30, 2022 20:37
Show Gist options
  • Save birinder-lobana/67d937f87c85595f965c70ab10269f04 to your computer and use it in GitHub Desktop.
Save birinder-lobana/67d937f87c85595f965c70ab10269f04 to your computer and use it in GitHub Desktop.
Create Contact, SMS Template and Send SMS
// Initiate the Openscreen node SDK and include the project ID that you recieved using the Openscreen dashboard
const { Openscreen } = require("@openscreen/sdk");
require('dotenv').config();
const os = new Openscreen().config({key: process.env.OS_API_KEY, secret: process.env.OS_API_SECRET});
// Obtain projectId from the Openscreen Dashboard
const projectId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
// Capture scanId from the QR code scan
const scanId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
async function main(){
// Create a new contact
const contact = await os.project(projectId).contacts().create({
firstName,
lastName,
cellPhone,
consent: {
url: "https://www.openscreen.com/legal",
consentedAt: date.now(),
consentType: 'SMS',
}
});
// Obtain contactId from the response
const { contactId } = contact;
// Create an SMS template
const smsTemplate = await os.project(projectId).smsTemplates().create({
smsTemplateName = "Position",
body: "You are now at position 5, please make your way to the {{asset.name}} now.",
};
// Send SMS to contact
const sendSMS = await os.scan(scanId).sms().send({
contactId: contactId,
smsTemplateName: "Position",
};
}
main().catch((err) => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment