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.
Related
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.
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.
I'm trying to figure out if there is a way to uniquely identify the conversation an SMS is replying to without having to buy a new 'from' phone number each time. I know that one can store whatever you want in cookie or session storage, but those both expire in different ways. What I really want is somehow to pass or use an existing unique id for each separate conversation. So that I can map the messages to the right conversations.
I'm not sure but I wonder if its possible to send a expireless unique identifier to a webhook. So that I know which conversation it should be mapped to?
If not is there some way to use the conversation api to achieve the effect of tracking which sms messages belong to which conversations?
A common challenge, since SMS is a stateless, is to try and match up the specific request with the response. Twilio Studio's Send and Wait for Reply widget does this by only allowing one sent message (to the destination number) until there is a response OR the configurable timeout parameter expires, and then moving to the next widget, so keeping state of the interaction.
As you said, if you are attempting to have multiple simultaneous threads to the same destination phone number, you will need to use a unique From number to separate out the threads - from the received parties perspective, they don't see threading in their SMS client, and cannot pick which question to respond to.
Best Practices for SMS Message Logging
Additional Questions Q: Can a user send a customer identifier for a
message, or is only the Twilio-defined SID available?
A: Only the Twilio-defined SID is available.
We have a C# MVC app that sends and receives texts utilizing the Twilio API effortlessly.
We have a button that sends a text to one or multiple people FROM a certain department (HR) / Twilio phone number.
Our problem is- When a user responds to the HR text, how do we craft a conversation between the HR department workers personal phone number, and the original recipient. (So they can communicate right in the SMS chat)
We tried:
To create a 'Group MMS Chat' but that doesn't seem to be supported by Twilio (yet)
To store the senders personal number, and the Twilio registered number - to make our server act as a 'switchboard', but that wont work if two different HR workers send a text to the same person.
I have read the questions / docs here: But cookies don't feel like the proper answer.
Twilio: How to map an SMS reply to an original SMS
Send Group Message with Twilio
https://www.twilio.com/docs/sms/tutorials/employee-directory-csharp-mvc#handle-multiple-or-no-results
https://support.twilio.com/hc/en-us/articles/223136287-How-do-Twilio-cookies-work-
Please let me know if this is too broad / a bad question, and i'll try my best to fix it. I don't want to go to SO jail :)
Any help is greatly appreciated!
You might think about using twilio proxy service , the flow for that would look like this
Pre select which HR person number or numbers will be responsible for that communication.
provision a new twilio number (not the same one already used by the HR department) this number will be used for the duration on the conversation
Initiate a proxy session https://www.twilio.com/proxy
** This is a more expansive approach , because you will need a twilio number per each individual conversation
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