Twilio Studio — IVR and Chat Bots

Twilio Studio — IVR and Chat Bots

I’ve used Twilio for a while for pro­gram­mat­i­cal­ly send­ing and receiv­ing SMS mes­sages. There’s also a visu­al edi­tor called Stu­dio that can be used to make call and mes­sage flows:

It can be con­nect­ed to Twilio Autopi­lot to make AI-pow­ered bots. Tasks are trained with sam­ple phras­es. These sam­ple phras­es are vari­a­tions on what would be said to trig­ger an action e.g. ‘Call recep­tion,’ ‘Front desk,’ ‘Talk to a human.’

An exam­ple that comes to mind, is mak­ing a call han­dling sys­tem for an office. Rather than a voice menu that details each option fol­lowed by a num­ber, the caller could sim­ply say who they want­ed to talk to or what their request was about, and the sys­tem would han­dle it. This is far more respect­ful of the caller’s time com­pared to hav­ing them lis­ten to a long list of choices.

It works with SMS and voice calls, and seems a good way to build an IVR (Inter­ac­tive Voice Menu) sys­tem. TwiML can be used for more com­pli­cat­ed tasks, while still using Studio/Autopilot. The pric­ing is a lit­tle high­er than if you were to use a self-host­ed sys­tem, but there are so many com­pli­cat­ed func­tion­al­i­ties it seems well worth pay­ing the extra, as it would save time and reduce complexity.

I built a remote con­trolled car that used Twil­io’s cell­phone ser­vice. You can read about it here.

Telepresence Internet Controlled 4G/LTE Long Range Robot Car

Telepresence Internet Controlled 4G/LTE Long Range Robot Car

For a long time I have want­ed to build a remote con­trolled robot car capa­ble of being con­trolled via the Inter­net, at long ranges using 4G/LTE cel­lu­lar con­nec­tiv­i­ty. So I did.

I used a Rasp­ber­ry Pi 3B+, an Adafruit DC and Step­per Motor Hat, and a Log­itech C930e USB UVC web­cam.

Build­ing the robot
Chas­sis with four motors
Chas­sis with four motors and top sec­tion attached
Com­plet­ed robot 
Com­plet­ed robot

The robot is capa­ble of con­nect­ing to the Inter­net using Wi-Fi. I was able to slight­ly increase the effec­tive Wi-Fi range by using a Mikrotik router and alter­ing the hard­ware retries set­ting and frame life set­tings. The inten­tion was to quick­ly recov­er from trans­mis­sion errors and avoid con­ges­tion. This dis­card­ed video pack­ets that could not be deliv­ered in real time, and kept the net­work clear for when trans­mis­sion would be suc­cess­ful. I also used ipt­a­bles and man­gle to alter the DSCP of the live video stream pack­ets with the same intention.

To enable a long range con­nec­tion, I used Twilio Pro­gram­ma­ble Wire­less to con­nect to local 4G/LTE cel­lu­lar net­works. I sub­stan­tial­ly low­ered the data rate to around 250 Kbps to make trans­mis­sion more reli­able and reduce costs, and was able to get a vir­tu­al­ly flaw­less live feed.

Twilio Wire­less Inter­net of Things Starter Pack
Mon­i­tor­ing 4G/LTE data usage with Twilio Pro­gram­ma­ble Wireless

The live video and audio stream uses FFMPEG for com­pres­sion and stream­ing, and has a pletho­ra of set­tings to tune. I took the time to tune bitrate, buffer­ing, keyframe inter­val. I also ensured the web cam­era was able to native­ly encode video with UVC at the select­ed res­o­lu­tion to reduce the load on the Rasp­ber­ry Pi’s CPU. Video laten­cy was often under a sec­ond, which is impres­sive espe­cial­ly con­sid­er­ing the round trip involved.

Robot remote­ly con­trolled via the internet

The con­trol sys­tem uses Let’s Robot (now Remo.tv), based at Cir­cuit Launch in Cal­i­for­nia, which has a com­mu­ni­ty of robot builders who love to cre­ate and share their devices. The pro­gram­ming lan­guage of choice is Python, and I also linked to an exist­ing API I had cre­at­ed in JavaScript with Node and PM2.

Mission 1

Mis­sion 1 — 30 minute Night Voyage

The first 4G/LTE long range mis­sion was suc­cess­ful, and the web­cam was good enough to be used at night. Dif­fer­ent mem­bers of the com­mu­ni­ty took turns to dri­ve the robot. It didn’t always dri­ve straight, so we had to dri­ve for­ward and turn to the left at reg­u­lar inter­vals. The robot drove for around 30 min­utes, and then got stuck when it fell down a side­walk. I had to quick­ly dri­ve to retrieve it =)

Mission 2

Mis­sion 2 — Involved Drama

The sec­ond mis­sion was intend­ed to dri­ve from my loca­tion to a friend work­ing at a local busi­ness. How­ev­er half way through the mis­sion, a sus­pi­cious mem­ber of the pub­lic grabbed the robot, threw it in a trash can, and called the police. I wait­ed for the police and calm­ly explained that the robot was an edu­ca­tion­al project in telep­res­ence, and also told the per­son report­ing the robot that there were no hard feel­ings, despite inter­fer­ing and dam­ag­ing my per­son­al property.

Police!

Mission 3

As part of the com­mu­ni­ty site, it is com­mon to leave your robot open to be con­trolled. While unat­tend­ed, a sneaky indi­vid­ual drove my robot into a void of the house and man­aged to get it cov­ered in spi­der webs and oth­er filth, as you can see below. Thanks.

Cov­ered in cobwebs
Very dirty

I found that cats were very curi­ous about the robot invad­ing their ter­ri­to­ry, as you can see below: 

A curi­ous cat inves­ti­gates the robot

I was very pleased with how the project worked, and had the oppor­tu­ni­ty to use Python, Node, and fine-tune wire­less net­work­ing and live video stream­ing, and of course remote­ly con­trol the robot as I had want­ed to do for a long time.

If you want to build your own robot, the guide to ‘build­ing a Bot­ting­ton’ is a great place to start.

Update: Twilio saw this post and gave me a $20.00 cred­it. Thank you 😁