Messaging services that can cooperate with programmable robots may feel like enchantment. Nonetheless, it’s an enchantment that codes can summon once you get under the hood a bit. To give you an example, we will take a gander at Misty’s Photo Booth aptitude, which Misty Robotics demonstrated at this year’s Twilio SIGNAL 2019.
The skill works like this – you can send an SMS to request that the Misty robot snaps your picture. At the point when Misty gets your content, she stops what she’s doing, goes to take a look at you, and captures your image with the camera in her visor. At that point, she sends the image right back to your phone through MMS.
To demonstrate how this works, we’ll separate what occurs behind-the-visor of Misty’s Photo Booth capacity, from your finger contacting send, to your picture arriving back on your phone. It investigates the connections between each help the aptitude consolidates, and it explains two or three significant squares of the JavaScript code that controls Misty’s reaction.
First, let’s focus on the Twilio Function:
Twilio Function -> PubNub
Generally, PubNub comes into action whenever the Robot Hacking process is invoked. In such cases, the robot usually responds with more sleepiness.
PubNub gives a constant informing API that engineers can utilize employing HTTP correspondence conventions, taking into consideration speedy correspondence between a broad scope of machines. At the point when you use PubNub’s informing API, you make a data channel — like a chatroom for gadgets — that various devices can buy in and distribute messages to.
While PubNub gives SDKs to a couple of extraordinary dialects, we get along fine and dandy in the Photo Booth ability with fundamental HTTP demands. At the point when you structure another “application” in PubNub, you get special API Keys for buying in and distributing to that application. To distribute information, we send a POST solicitation to:
https://ps.pndsn.com/publish/<publish-key>/<subscribe-key>/0/<channel-name>/0?store=0&uuid=<client-name>
You’ll see that the PubNub URL fuses distribute/buy-in keys, a customer name, and a channel name. Likewise, JSON-based format is generated that distributes at the time when the solicitation is sent. For our circumstances, that message resembles:
{
‘phNumber’: contact,
‘type’: ‘photo’
}
SMS -> Twilio Autopilot
To stand apart enough and stand out barely to be noticed, the client messages a phone number snared to Twilio’s Autopilot administration. In case you’re new to Autopilot, at the point when you message this unique number, Twilio advances your message to the Programmable Messaging channel identified with an uncommon Autopilot “bot.” Every Autopilot bot you make can perform at any rate one “errands.”
Autopilot deals with the errand named “take_picture” that is considered to be the main capacity specifically for photograph-based abilities.
The following stage is to program what the robot does when the take_picture undertaking triggers. Potential activities fuse communicating something specific back to a particular client, tuning in for reactions, or assembling and putting away data. On the other hand, if the implicit activities aren’t adequate, you can program undertakings to redirect to different administrations. That is the thing that occurs in the Photo Booth ability. Whenever the take_picture is invoked or called, frequently, it calls the redirect function for running a Twilio Function.
Autopilot -> Twilio Function
Twilio Functions are serverless capacities for taking care of inbound Twilio interchanges.
The Twilio Function in Photo Booth expertise accomplishes several things. To begin with, it designates the client’s telephone number to a variable. At this specific time, API for Twilio is called for sending Client with SMS : [….] Time to Pose. Finally, this will use the POST services to Client’s Mobile to PubNub Station, which is waiting for tuning for a new message.
Following is the code that is representing Twilio Function code for the Photo Booth:

With the Autopilot Bot and Twilio Function set up, we’re ready to look at PubNub, the service that notifies Misty to take a picture.
PubNub -> Misty
Before we take a gander at the robot’s expertise code, it’s helpful to comprehend what we mean by ability. Aptitude is your JavaScript code in the Misty Robo-section, which is running locally on the robot. Every fitness requires a JavaScript code record, with the JavaScript Misty executes when the ability runs, and a JSON meta-document, with other information about the expertise.
Cloudy’s installed JavaScript API gives procedures for buying into information from sensors and various occasions, and you characterize the callbacks for dealing with this information in your expertise code. This API moreover incorporates procedures for directions like moving the robot, playing sounds, utilizing her sensors, and sending web demands. Thus, Misty usually gets the complete information from PubNub in the Photo Booth.
The functionality is included, which resembles that whenever any of the code is being sent to her, the code should be easily controlled and also be in the running stage before sending the process takes place. In addition to it, Misty also tunes in for new SMS alerts just by sending solicitations to PubNub channel. This works employing the misty.SendExternalRequest() strategy from the Misty JavaScript API.
Each solicitation Misty sends will break if it doesn’t get a reaction following 20 seconds, and there’s no confirmation that someone will send Misty a message inside that time allotment.
In the JavaScript document for Photo Booth ability, that code resembles this:

The outputExt() work evacuates the telephone number and the estimation of the sort parameter from the message the Twilio Function sends. On the off chance that it is, she runs a square of code that has her move her head to confront the client, change her presentation picture, and play sounds to tell the client what’s going on.

Misty -> Imgur
Typically, we pass base64-encoded strings for images that we are sending to Misty for dealing with taking pictures. _TakePicture() is the method or function that is being used for passing the base64-encoded string whenever the image transformation is being converted to uploadImage() work function.
Once the uploadImage() work is invoked, Misty displays the generated image on a private Imgur collection. There are a couple of picture sharing administrations we could use to have these photos, yet Imgur’s API completes two things that make it ideal for the Photo Booth Skill.
Bypassing this returned URL again into Twilio’s MMS API, Misty can send the image to the individual who mentioned it.
The code for managing this in the Photo Booth aptitude looks something like this:

Summary
In this post, we discussed how to linkPubNub and Twilio’s informing APIs, Imgur’s photograph sharing administrations, and robot-icizied JavaScript code to make a Photo Booth aptitude for Misty. At the point when we use this expertise:
- Somebody makes an impression on Twilio telephone number
- Twilio forwards the message typically to Twilio Autopilot bot
- Our Autopilot bot scrutinizes the message, distinguishes the undertaking, and occupies to Twilio Function
- The Twilio Function posts the client’s phone number to PubNub channel
- Cloudy, who’s been running the Photo Booth expertise all the while, pull down the message from PubNub
- Cloudy repositions her camera and snaps a photograph
- Cloudy transfers the photograph to a private Imgur collection and shouts to the Twilio API to send it as an MMS to our client
Sending your robot a book is a pleasant way to deal with the request that it accomplishes something. When does the robot answer with an image of its preferred individual? That is friendly.