How to track different conversation threads between 2 participants in twilio? - twilio

I have an application which uses Twilio to send SMSs.
There is a situation where the application sends multiple messages to a person, for example a message with info about product P1, then another message with information about product P2, and so on. So my question is, when the person replys the SMS, how could I know to exactly what SMS he is replying?
Or is it possible that each SMS that my application sends to the same person creates different conversations in Twilio, so I can track each response per each different SMS?, if so, how I can do it?

If you trigger the SMS messages by API it's hard to know what messages the customers answer.
We got to solve this problem using Twilio Sync (https://www.twilio.com/docs/sync/api/document-resource) which is basically cloud storage, so when we need to trigger an SMS or Whatsapp message, we save some information on Twilio Sync, like Twilio number, client number and the messages that were sent.
When the customer answers the message, we send him to a Twilio Studio that runs a Function that read the Sync document and check if this customer comes from a message response, if yes, we get the triggered message and added on the conversations, so we know the message that customer answered.
The Sync isn't a database and has a limit, so depending on your message volume, it can not work well.

Related

Linking an SMS reply to the original message

We want to be able to send an SMS using Twilio and the person receiving should be able to reply to the message thread.
How can I link the reply to the original message? (In e-mail we just put the thread->id in the reply address)
The person receiving could be in multiple threads.
Twilio seems to suggest cookies but I don't see how this could work.
Mick
Twilio developer evangelist here.
There's nothing in SMS that allows for a message to be replied to directly. If you check your own phone and its SMS application you will find that you can't reply, just send another message in chronological order.
One option you have is to buy and use multiple numbers to communicate with your users. You only need as many numbers as you have open threads with a user, but that is a way to segregate messages between your application and an end user.

twilio conversation tracking id

I am creating a chat application with twilio but having an issue tracking conversations among multiple users and multiple conversations.
Example:
conversation -> userA & userB
conversation2 -> userA & userB
When userA sends a message to userB in conversation2 when I receive a SMS message from userA how do I map it to conversation2?
What I am expecting:
What I am looking for is an ID that is either provided by me or generated by twilio and given to me when I send the SMS. Then when I receive a SMS from twilio I can match it to a conversation by looking at the ID stored when the SMS was sent.
thank you!
Twilio developer evangelist here.
SMS does not have threading baked in, so this is not possible with just one phone number. You can prove this to yourself by opening the SMS app on your phone and trying to respond to the second to last message you received from someone.
You have two options:
You insist that your users include a specific ID within messages in a thread so that you can parse the message and extract the ID to tie the threads together.
You conduct separate conversations between the same users using different Twilio numbers. This way you can tie the thread together using the number that was used.
Let me know if that helps at all.
I know this response may be too late, but here goes anyway...
Conceivably, if Conversation 1 and Conversation 2 both are between different parties. You could create a mapping table of the endpoint phone numbers and just map the messages to the corresponding phone number.
Example:
Conversation 1 = UserA(1-234-567-8910) => UserA(1-234-567-8911)
Conversation 2 = UserC(1-234-567-8912) => UserD(1-234-567-8913)
If UserA sends a message, it will be forwarded to UserB, and vice-versa. Same goes for Conversation 2.
On the server side:
Upon the initial connection, the server would map that UserA wants to talk to UserB. This would remain in the lookup table until UserA stops wanting to communicate with UserB.
This would require that each user could only have one conversation going at a time, which may not fit for the purposes of the initial poster, but I hope that it will help someone.

Twilio: How to get answers from message log with just phone number

I want to get received messages of the same day of a phone number with the help of API or anything.
(I have purchased ofcourse a phone number)
**
Requirement :
**
I have a twilio app which sends 5 questions to 1000 user and users reply's to it. Like a survey. App is deployed on Azure.
I will get 5000 messages in log.
I am planning to retrieve messages by phone number and update my database from the user.
Implemented :
Implemented this https://www.twilio.com/docs/guides/sms/how-to-receive-and-reply-in-csharp. Any other idea for the requirement is also appreciated.
Twilio developer evangelist here.
I see that you've implemented the basic flow for responding to incoming SMS messages. If you are implementing surveys across a number of users my advice would be to expand on that application.
Firstly, you would need to run through your database to get all your users' phone numbers and send the first question to all of them using the Twilio REST API to send each a text message.
Then, when you receive an incoming message from one of your respondents you can find out the number that sent the message by inspecting the From parameter on the incoming request body. You can then look up your user in your database by phone number and save that response for them. Then you can use the TwiML <Message> to respond to the user and send them the next question.
This way you can collect the responses as they come in, rather than call the REST API to list all responses.
Let me know if that helps at all.

Fetch MessgaeSid (SmsSid) of the message i send. When Someone replies to my message

I am Developing a Sms Convesation Application using Twilio API. What My Application does is It Send SMS to Mobile device prompting some options to chose. Users should reply back with anyone of the given option. What i want is when someone replies back to my application, I want the MessageSid of sent message(Message sent from Application). How can I acheive this? Please Help me
Twilio evangelist here.
There is no way to get the sid of a previous message from an inbound message since we don't track that. The SMS protocol has no facility for a "conversation" in it so we don't know that the inbound message is a "reply" to anything.
What you need to do is store in your app the fact that you sent a text message to a specific phone number. Then when that user replies from that number you would be able to know that you had previously sent them a message.
Hope that helps.
Devin
I don't believe this is possible. SMS messages are "stateless", much like HTTP requests. The only thing you could use like a session id would be the phone number. What about tracking conversation history by mapping an array of MessageSids to the phone number?

how to associate received sms messages (via twilio) to specific user in my rails app

I'm making an app that sends text messages to a group of people and then people can respond to the text. I want to be able to record the response, know who sent it, and associate it with the user who sent the original message. I've gotten the sending working, and I've begun putting together receiving sms messages but i'm confused. If twilio sends a post request to my server with the from number and message, how will I know which of my users sent the original message?
what if two different users send a message to the same person around the same time? what's the best way to handle this? do I need a separate 'to' number for each of my users? seems like that would get quite expensive. also, if each user has multiple campaigns (messages), how would I associate a response to a specific campaign?
i'm building a rails app.thanks
You'll want to use a different Twilio number for each contact a user sends to. This will establish a unique mapping between the 2 mobile devices and a Twilio number. This allows you to forward incoming messages sent to the Twilio number back to the appropriately mapped mobile phone. You'll do the lookup on your mapping based on who the incoming message is From.
You won't need a Twilio number for every one of your users, but you will need a pool of numbers which is the maximum number of contacts a single person can make.
There is an article on Twilio's site which gives additional information:
https://www.twilio.com/help/faq/sms/how-can-i-have-users-send-text-messages-to-each-other-over-twilio

Resources