- Install all dependencies by running:
npm install
- Copy webchat-appConfig.sample.js in public/assets folder and configure accordingly to use your Twilio account
cp public/assets/webchat-appConfig.sample.js public/assets/webchat-appConfig.js
- Start Flex UI by running:
npm start
- Build project for production:
npm build
Flex -> Accept incoming SMS -> Twilio Studio HTTP POST -> Azure Function (Create Programmable Wireless Command in Node.js) -> Receive Command with Arduino MKR 1400 -> Blink on-board LED
Flex agent receives a new SMS prompt and when a new chat starts an HTTP POST is routed in a Twilio Studio Flow.
When the Flex agent accepts a new incoming SMS, it routes to the Twilio Studio Flow named "Messaging Flow". A trigger is generated by the "Task Created" outlet and the output routes to an HTTP POST Request, executing an Azure Function from Studio.
The Azure Function creates a new Programmable Wireless Command using Node.js. More information about how to create an Azure Function using the Azure CLI can found on the Microsoft website.
module.exports = async function (context, req) {
const accountSid = 'TWILIO_ACCOUNT_SID';
const authToken = 'TWILIO_AUTH';
const client = require('twilio')(accountSid, authToken);
client.wireless.commands
.create({sim: 'SIM_SSID', command: '1'})
.then(command => console.log(command.sid));
};
The Arduino MKR 1400 receives a Command created by the Azure Function, filters the data and then illuminates the on-board LED to notify the agent that an SMS conversation has started.
#include <MKRGSM.h>
GSM gsmAccess;
GSM_SMS sms;
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("SMS Messages Receiver");
boolean connected = false;
gsmAccess.begin();
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
}
void loop() {
int c;
if (sms.available()) {
Serial.println("Message received from:");
if (sms.peek() == '#') {
Serial.println("Discarded SMS");
sms.flush();
}
while ((c = sms.read()) != -1) {
if (c == '1') {
Serial.println("woo!");
// Turn on LED
digitalWrite(LED_BUILTIN, HIGH);
delay(5000);
// Turn off LED
digitalWrite(LED_BUILTIN, LOW);
delay(3000);
} else if (c == '0') {
Serial.println("sad!");
} else {
Serial.println("incorrect message");
}
}
Serial.println("\nEND OF MESSAGE");
sms.flush();
Serial.println("MESSAGE DELETED");
}
delay(1000);
}