After I send a sms message to a particular phone number, how do I track the potential conversation?
I see that there is the URL within my Twilio account that Twilio sends http requests to.
Do I just keep checking this URL and go through the messages from the user, using the "from" field in the JSON data?
Twilio developer evangelist here.
When someone responds to your Twilio number then that URL you set in your account will receive a POST or GET request (your choice) with all the details of the message. You don't need to check that URL, the information will come to you.
You could then use the REST API to gather the messages that have gone back and forth between your app by calling for all the messages sent to the user's number and all the messages received from the users number.
You can also, in response to an incoming SMS message, set cookies that can be retrieved as part of the HTTP request. So, if you want to save some data between messages that's a way to achieve that. Here's a guide on using cookies to track SMS conversations.
Related
We are using Twilio for sending outbound message to our customers.
When we send Outbound SMS to Customer then we are storing Outbound message details in our Database.
Also we have implemented Inbound SMS. So if we receive any inbound SMS from customer then we are creating inbound message record in database.
Now our requirement is that if sent a sms to Customer and then customer replied to that outbound message then we have need to store Inbound SMS under Outbound SMS, so we can relate inbound message with Outbound message.
Is there any way to identify in twilio that inbound message that we have received is related to which Outbound message (may be can we use any unique identifier)?
Thanks,
Raj
Twilio developer evangelist here.
There is no affordance in SMS to reply to specific messages. You can see this yourself by opening your SMS app on your phone and trying to reply to the second to last message you received from someone. It's simply not possible.
So, you can either make the assumption that if you have sent a message to a user that their next inbound message to your number is in response to that.
Or, you can use multiple numbers to send different messages, associating responses based on the number that sent/received the message.
Hope that helps.
Full disclosure I work at Till Mobile.
I believe you can achieve this using our A2P SMS platform (which happens to utilize Twilio).
Till creates a unique id for the to and from phone number combination when an outbound message is sent.
When an inbound message is received it is tagged with the same unique id. In the Till API this id is called the project_launch_guid.
Using the Till API
You can get a free username and api_key via https://tillmobile.com/
Send the outbound message
curl -H "Content-Type: application/json" -X POST -d '{
"phone": ["phone_number"],
"questions" : [{
"text": "Welcome to the customer appreciation program. If you have a question please respond.",
"webhook": "http://requestb.in/1ilpbfd1"
}]
}' "https://platform.tillmobile.com/api/send?username=username&api_key=api_key"
Which returns
{
"project_launch_guid": "some_guid",
...
}
Retrieve the inbound message
If a user later responds the message will be POST'd to the webhook defined above in this format including the same project_launch_guid returned from the send:
{
"project_launch_guid": "some_guid",
"participant_guid": "585897f2-2c30-43f5-8f6b-7c243e8ac4b0",
"participant_phone_number": "phone_number",
"question_guid": "685897f2-2c30-43f5-8f6b-7c243e8ac4b0",
"question_text": "Welcome to the customer appreciation program. If you have a question please respond.",
"result_guid": "885897f2-2c30-43f5-8f6b-7c243e8ac4b0",
"result_timestamp": "2016-11-27T11:57:14.060474",
"result_answer": "How do I redeem my points?",
...
}
Note: the webhook is optional. If it is not provided the inbound message can be retrieved via our results API:
curl "https://platform.tillmobile.com/api/results?username=username&api_key=api_key&project_launch_guid=some_guid"
Using either the webhook or results API the project_launch_guid can be used to tie the outbound and inbound messages together. The result_answer attribute value will contain the user's inbound message.
FYI We treat each send like a session. They persist indefinitely unless another send is created with the same to and from phone numbers. In that case the second send is queued behind the first and a configurable TTL is set on the first.
We have more documentation available here https://till.readme.io/docs/
Don't hesitate to let me know how we can assist further.
I have built an app that sends out an SMS using the twilio number(the one assigned to me) when a message is sent I receive the SID number which is inserted into the db, along with some other general information, however I do not know how to connect the received SMS SID to the sent SMS SID that tells the system that user has responded....how does someone connect the outgoing message to what is received?
UPDATE:
Hello Devin, Thanks for the response! however, this does not help me much as I might send lets say one of three different people multiple messages in an hour.
my app is a notification app...basically it is a form that a user fills out with some basic info. one of these fileds they choose is a drop down of three different people(who the message will go to) they send the message. my app then inserts the form data explained above along with the SMSID that is returned by you guys into a DB.
the user(one of the three people descibed above) that was sent the notification above responds to the message, meaning that Twilio hits my "Request URL" and I save all the information that is returned by the user...however, and where the problem actually lies is that the SMSID for that reply is not the same as the SMSID of the sent notification...therefore I have no way to connect the SMS that was sent to the user with their response. I have looked at the cookies option and that is not what I am needing...actually your documentation actually acknowledges this issue but does not offer a solution as seen here under "Application Initiated Conversations"
https://www.twilio.com/blog/2014/07/the-definitive-guide-to-sms-conversation-tracking.html
So if you know of a way around this, I would love to hear it for sure :)
Twilio evangelist here.
The SMS protocol has no concept of a "conversation". Each message sent is unique and has no knowledge of messages sent before or after it. Twilios SMS Sid is simply a unique identifier for an individual message.
The typical way to solve this is to use the To/From phone number pair as the unique identifier of an SMS conversation. When you send your first outbound message, store the To/From phone number in your database. When the user replies Twilio will tell you what number they sent the message to and from and you can use that information to look up the original outbound message in your database.
If a "user" can be involved in several different conversations at once you either need to use a unique phone number for each seperate conversation (allowing you to use the technique above), or you need to have the user include some type of conversation ID in their reply (which you can use as the unique identifier).
You can buy a pool of numbers and as each conversation "ends", recycle the number for a new conversation.
Hope that helps.
I am new to Twilio API.I have trial account and I have sent Message using Twilio Rest API successfully and received message from number i.e Message as:DM-062107 and body :- Sent from your Twilio trial Account-Hello.
Now I can't able to reply this message.can any one help me to how I can reply to this and how I know that message is received.
I have contacted to Twilio technical support for same problem and get the response. Check the reason why reply option is not enabled:
Although Twilio supports sending outbound messages internationally using toll-free numbers, your Indian number may not support sending inbound messages to US toll-free numbers. I will recommend checking with your mobile carrier to see if sending messages to US toll-free numbers is supported. If not, I will recommend using a regular US number instead of a US toll-free number and kindly retest.
Twilio Evangelist here.
So, to reply to message you just send a normal SMS from your phone to the number. The way Twilio handles this is using a 'webhook'.
If you log into your Twilio account, click on the 'Number' tab, you'll see you have a telephone number there (the same one you sent an SMS with):
Once you've clicked on the number, you'll see a screen with some other details:
Here you can configure your webhook. This is basically a URL that Twilio will send your message to. So if you configure that to point to the URL of some application you have written, you'll receive an HTTP Post or Get request (you can configure which) with the contents of the message, who it is from, etc.
You can then reply to this message with Twiml, which is just XML:
<Response>
<Message>
This is the message that is sent in reply!
</Message>
</Response>
And using this you can build up a conversation!
There are a lot of details on Twilio's website with quick starts etc. There is even a video that talks it through.
Hope this helps.
I would like to send a text message survey (eg. "How happy were you with X service? Reply 1 for satisified, Reply 2 for not satisfied") to multiple recipients. From the responses, I would like to create a report on the recipients that responded 1 vs the ones that responded 2. What is the best way to do this with the Twilio API? Does my app need to store the results from my incoming SMS message or does Twilio store these so I can query the results? If the former is the case and TwiML is involved, how do I parse the response and store the result? Thanks!
** Disclaimer: Twilio evangelist here **
Chirag:
So it sounds like you have two requirements here:
Use Twilio to send outbound text messages to different recipients
Capture a users reply to that message
For the first requirement, you can start by going to Twilio.com and signing up for a new account. Its free to start and we give you a Twilio phone number you can use to start to build your app. Once you have the Twilio phone number, you can use the REST API to start sending outbound text messages from that Twilio phone number. We have a quickstart that shows you how to do this:
http://www.twilio.com/docs/quickstart/php/sms/sending-via-rest
Note that this link goes to the PHP sample, but you can use the drop down at the top of the page to pick from other stacks like .NET, Java, Python or Ruby.
Once you've sent an outbound message you need to capture the replies to that message (your second requirement). Twilio uses something called a webhook to notify you about incoming SMS messages.
A webhook is basically a URL exposed by your application and associated with your Twilio phone number. You can configure the URL associated with your phone number in the Twilio dashboard.
Each time we receive an incoming SMS message on your Twilio phone number, we will make an HTTP request to that URL. As part of that HTTP request we send along metadata about the inbound message like the phone number that the message was sent from and the Body of the message. The full list of parameters we send is here:
http://www.twilio.com/docs/api/twiml/sms/twilio_request
Now your app can pull those parameters out of the request and do whatever it wants with them. Since we already are sending the body of the message as we receive it, Tims suggestion of tracking the responses based on the From parameter and storing the message body in your own database is a good suggestion.
This quickstart shows receving an incoming text message, grabbing the From parameter and then responding by sending back from TwiML:
http://www.twilio.com/docs/quickstart/php/sms/replying-to-sms-messages
In your case, if you don't want to reply to the incoming message, just omit the TwiML response.
Hope the helps. Lets me know if you need more info.
Devin
Track the responses using the From parameter (and using Body to identify the selection). Yes, Twilio stores those messages, and you could query the API - but it's likely better to just store it in your own database.
I hope this gets a response.
Say Person A sends an SMS to a shortcode in a certain syntax. How could a confirmation SMS be sent to Person A's mobile phone automatically ("Your message has been received successfully!"), after determining that the SMS received from Person A is in the correct syntax? I'm a total newbie when it comes to SMS - so if anyone could describe the entire end-to-end process/architecture that could make this happen, I'd be grateful!
You'd have to find a gateway provider who handles the receiving and the sending of messages for you using a defined API talking to a script/application in the language of your choice.
You usually receive messages on a number defined by the gateway provider. Incoming messages will trigger a call to a URL defined by you. Behind that URL will usually be a script that then performs the desired actions (e.g. parsing the message and sending an automated response SMS through the gateway provider.)
SO questions related to SMS Gateways:
Sending an SMS myself
SMS from web application
BulkSMS provides facilities for you to both send mobile terminating (MT) messages and handle receipt of mobile originating (MO) messages.
You can request a short code, which your users then send MOs to. The message can then be relayed, via a simple HTTP request, to your web server. You application then determines a suitable response and replies via SMS by calling the MT API of BulkSMS.
There may be restrictions and legislation applicable, depending on where you are, where your users are and the networks the messages are passing through. They can provide assistance here too.
International incoming numbers http://www.bulksms.com/int/w/solutions_incoming.htm
Receiving messages via HTTP http://www.bulksms.com/int/docs/eapi/reception/http_push/
Sending API http://www.bulksms.com/int/docs/eapi/
Short codes in South Africa http://bulksms.2way.co.za/w/solutions_psms.htm
Hope this helps