Reputation: 181
We're a delivery service company. When an order is placed, we wish to send out a delivery job offer to our drivers. The jobs are first-come-first-serve.
Orders are processed on our NodeJS server. What would be an efficient way to text (SMS) each of our drivers while using Twilio Autopilot to handle the conversation (asking for job details)?
I can't seem to find a way for instructing Autopilot to initiate the conversation for a specified outbound phone number. I've used twilio.messages.create()
to send an SMS to a driver (with a job offer) from the same number as Autopilot. But when drivers reply, Autopilot has no context to the original question.
Upvotes: 2
Views: 1102
Reputation: 3300
I am adding another answer as the above answer is with an old version of Twilio Studio and no longer works.
You can initiate a call with the Twilio REST API in the programming language of your choosing, like JavaScript, C#, PHP, Ruby, Python, or Java. Alternatively, you could use a cURL request where you pass in the URL corresponding to whichever communications channel you would like the conversation to be on. First, you'd go to your Autopilot bot console and select Channels
on the left-hand bar.
Then you'd pick, for example, Programmable Voice
as shown below.
Copy the URL for Programmable Voice
.
In the cURL request below, replace the corresponding variables with your Account SID and Auth Token (which can be found in your Twilio console, phone number to call, Twilio phone number, and that Programmable Voice URL in Url
.
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
--data-urlencode "To=PHONE-NUM-TO-CALL" \
--data-urlencode "From=TWILIO-NUMBER" \
--data-urlencode "Url=YOUR-AUTOPILOT-URL" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
Running that cURL request would initiate an outbound call whose first message is the initiation task of your Autopilot bot and then the bot would continue the conversation. As a default this is set as the greeting
task.
Again, this is the most recent way to initiate a conversation with a Twilio Autopilot bot. You could do it in a different programming language or also edit it to be a SMS, more info on that here.
Upvotes: 3
Reputation: 3300
Twilio developer evangelist here.
You can initiate a session with Twilio Studio! You can message the user without the user greeting the bot by connecting the trigger widget's Rest API
trigger event to either a make outgoing call
or send message
widget, as shown below.
Then, if the call is answered or the message is sent, you can connect those actions to the Send to Autopilot widget.
Lastly, under the config section of your Send to Autopilot widget, put in the Collection task you want to run when the outbound call or message is initiated by your Twilio client and not the user.
Alternatively, you don't need Twilio Studio: you can also hit the REST API https://www.twilio.com/docs/autopilot/api to kick-off a dialogue.
Let me know if this helps :D
Upvotes: 5