How to find relation between send and received message in twillio - twilio

I am using Copilot API of twillio to send sms. so i am able to send sms to end user. Now if user reply to that sms, i am receiving the callback (PHP Script). Using that callback URL, i am able to get the reply message.
Now i want to do is, i am trying to find a relation between sent and received(which end user reply) message. so i can then forward the reply message to their sender.
I will have UI like below, where user enter the message and number where he wants to receive reply.
But the problem is i am not able to find relation between send/receive message.
Any advice will be helpful.

Twilio developer evangelist here.
Other than storing the information on your server upon sending/receiving a message, you could make use of the cookies stored at Twilio.
When Twilio makes a request to your server and it returns a cookie (a Set-Cookie HTTP response header), Twilio stores this cookie and associates it with the From and To numbers for the incoming call or SMS message.
A little caveat to this is the fact that this cookie is only stored for four hours, so unless that works for you, I'd suggest using the from & the to as composite keys to find a relation.
Hope this helps you

Related

Send customized bulk SMS with twilio

I want to send different messages to multiple users at once. I read the article here: https://www.twilio.com/blog/send-bulk-sms-twilio-node-js-html but it mentions nothing about sending customized messages. The only difference in my messages is the user's name.
The best solution I can think of is to create x number of API calls to send messages to x numbers. I believe that's going to be time taking. Is it possible to do it with one API call?
Twilio developer evangelist, and author of that post, here.
You are right, there is not currently a Twilio service that allows you to send bulk messages with customised messages with one single API call. You will have to make an API call to the messages resource for each message you want to send.
When sending messages in bulk, I recommend you read and understand this article on Twilio rate limits and message queues. That will ensure you are successful in sending your messages.

Verify SMS received in Twilio is from a real phone and not a spoofed POST request

I'm creating an app where a user can sign up for phone notifications. We're verifying users by sending them a text message and then having them respond "YES" or "NO" to receive text messages.
However, we're concerned that users might be able to spoof sending a message to our webhook by using a POST request to it with just enough data to verify them. Is there a way in Twilio to detect if an incoming request is from Twilio or not?
This is possible with more information here - X-Twilio-Signature. There are also a few different blog posts detailing its use, for example, How to secure Twilio webhook URLs in Node.js.

Twilio SMS: Is there a way to recognize status updates from SMS generated with SMS API vs TwiML <message/> responses?

My service is sending SMS to users in two different ways:
The main one is the SMS API, my service sends a request to Twilio with all the SMS data, and get the SMS id in the response. With that id it waits for the sms status updates to check if the text was delivered.
But there is another way, as a response to a user sending a text to my service, using a TwiML <message> in the Response. In this case, I send back a SMS to the user, but there is no SMS id to check for status updates (because the service sends the text in the response, not in the request).
So in this scenario, there are status updates from SMS ids that the service can not recognize.
My question is: is there a way to get the SMS id from TwiML <message>s? Or be able to recognise which status updates come from TwiML messages?
Or my only way to do this is to always call the SMS API and do not return a text using TwiML for this scenario?
Thanks in advance!
Twilio developer evangelist here.
The way to get an SID from replying to a message using <Message> is to wait for the status callback webhook. Of course, as you say here, when you reply that way you don't store the details of the message in your system. What you could do is wait for the first status callback webhook and if you find a message SID that you don't already have in your system, use the REST API to look up that message, save the details and be prepared for further status callbacks.
Alternatively, there is nothing wrong with using the REST API to send the message instead of <Message> and just returning an empty <Response> to an incoming webhook.

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.

Override Message Service inbound URL programatically

I have setup a trial Twilio account and have been investigating their
Programmable SMS service. Within my account I have also setup a Messaging Service. When I send an SMS I am able to set the URL I wish Twilio to send all delivery events (e.g accepted, sent, delivered etc) to, using a field called statusCallback. However, I am wondering if it is also possible to set the URL for which I wish to receive any replies to the message being sent, as part of the send SMS call? I know I can change the incoming request URL within the Messaging Services area of my Twilio account dashboard, but I would like to be able to set this URL on a per SMS basis, as part of the send SMS API call.
Does anyone know if this is possible? I cannot see anything in the docs to suggest it is but I wanted to know definitively.
I hope the question makes sense but if any clarification is needed then please let me know.
Thanks,
Paul

Resources