Get Whatsapp Number of user in Twilio autopilot - twilio

I am trying to create a chatbot using Twilio Autopilot which integrated with WhatsApp. So my flow is like, if user messages on registerd number, Twilio WhatsApp senders webhook will get trigger and it will call Autopilot chatbot task. Task will process the data and it will send reply.
In all above flow I want to capture the WhatsApp number of the user who is asking the question. that number I want in autopilot, so Autopilot will send that number to Twilio function and I want to save that number in my Database using external API's call from Twilio function.
How I will get WhatsApp number inside Twilio Autopilot chatbot for user who is asking questions?
Thanks in Advance

Autopilot can respond using static actions defined within the task, but it can also send a webhook request to fetch Actions JSON from your server. That webhook request contains details about the user you are talking with, including the parameter UserIdentifier which, in a WhatsApp chat, will be the user's WhatsApp number.
If you are currently responding to tasks from Actions JSON defined in the Twilio console, you can add a webhook by using a "redirect" action at the end of a set of actions to a URL you control and then responding to that with a "listen" action to wait for the next task. Alternatively, you could just set a URL for the webhook and respond with your Actions JSON from your own app.

Related

twilio webhook custom paramters

Is it possible to define custom data in outbound SMS/IVR call and receive same data back on callbackurl/webhook. I want to receive few custom parameters (apart from what twilio sends) when my webhook is called.
Try appending the custom data as URL query parameters to the URL you give Twilio to fetch the TwiML. SMS is a different animal, since it doesn't request TwiML like voice does.
How to Share Information Between Your Applications

Triggering a Twilio function to write a record in an external service (e.g. a CRM) whenever an sms message is SENT via Twilio

What the title describes can already be done easily via programs like Zapier, so I am hopeful that it can be done through Twilio functions directly.
Essentially, I have my CRM set up so that based on certain triggers, it sends a http POST request to the Twilio URL that controls SMS sending:
https://api.twilio.com/2010-04-01/Accounts/ + twilioAccSId + /Messages.json
For the most part, this works great!
I just want a way for Twilio to then respond by using a function to write a record into the CRM (using the CRM's APIs).
I would want the record written to include things like the delivery status of the message e.g. whether it failed, or was successful). I'm also open to exploring other ways where Twilio can transmit this outbound message info to the CRM through other means, and then having a function on the CRM then write a record!
Do you have the code to share of what you are attempting and the issue encountered? Or is the question more if this is possible? It is certainly possible.
You will use a statusCallback URL of your outbound POST to the messages resource, which will fire with the statusCallback messages and make an API call to your CRM to update the customer record accordingly. You can append a URL query parameter to your statusCallback, so you know which customer record to update.
Track Delivery Status of Messages
How to Share Information Between Your Applications
Passing Custom Information via Requests to Twilio

Twilio WhatsApp Autopilot - How to Start The Conversation

Is there any way to make the Autopilot start the conversation. What i need is, I have Customer Mobile Numbers and i need to send to them a automated WhatsApp Message. and based on there inputs, Autopilot response to them.
Thanks,
you should be able to initiate a conversation using one of your WhatsApp approved templates using the Twilio Messages resources. Once the user responds (and the 24 hour free form text opens), you can configure the Webhook for WhatsApp to execute your Autopilot assistant.
Twilio WhatsApp production sender and template creation
Twilio API for WhatsApp *(Send an outbound freeform WhatsApp Message)
WhatsApp - Autopilot Channel
Twilio developer evangelist here.
Welcome to StackOverflow!
You can initiate a session with 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, in your case, the 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, below.
.
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.
Let me know if this helps :D

How do I start an Twilio Autopilot chat session without the user needing to greet the bot?

How can Twilio Autopilot chatbot initiate a session with a user without the user greeting the bot?
I've tried exploring using Twilio Studio to kick off the conversation, but our application requires that the first interaction in the sequence must be a Collection Action. I can't seem to kick off that Collection Action without the user having greeted the bot.
An example would be that every day we would message the user with a question: "How many bananas did you eat today?". The user would then respond and Autopilot would parse the data and send to our system. The question can't be hardcoded in Studio because it will be dynamically generated on a daily basis. The question must be a Collection Action.
Twilio developer evangelist here.
Welcome to StackOverflow!
You can initiate a session with 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.
Let me know if this helps :D

HTTP GET request for user's phone number in fulfillment editor

We are setting up a chat bot through Dialogflow. A user will receive a weblink to the bot in a call or SMS sent through twilio. I'm wondering if it is possible for us to set up an HTTP get request to twilio in fulfillment so that we can set a context parameter to the user's phone number in the fulfillment inline editor in Dialogflow.
I took a look at twilio's api docs but could only find information on HTTP requests regarding numbers purchased or available for purchase through twilio.
So to clarify: in Dialogflow's fulfillment inline editor, we want to set a context parameter equal to the user's phone number that twilio called or sent the SMS to with a weblink to our chat bot.
Thanks!
Twilio developer evangelist here.
If I'm understanding right, you want to send a URL to a user via SMS (or over the phone?) which will link them to a web based chat with your bot. And you want to be able to link that chat back to the original phone number?
If that is the case, then the first thing that comes to mind for me would be to create a unique URL for each phone number you send this message to. If you store a link between the URL and the number it is sent to in a database somewhere, then when th euser clicks through to it you can recover the phone number and apply it to your Dialogflow context.
I don't believe you need to make any requests to the Twilio API for this aside from sending the initial SMS.
I hope this helps.

Resources