Twilio studio, initial sms message - twilio

In twilio studio, I'm trying to create a workflow to send an initial text if the person has never sent us a message before. I have already setup auto responses, but I can't get the program to check whether the person has “subscribed” or not. What am I missing?

you will need to create your own database to capture that metadata (firstContact=false or something similar) if they have previously responded and then respond with the appropriate message.
You can save this data to your CRM or a database, POSTing via the HTTP Request Widget or Run Function Widget (where you keep their opt-in records) and then refer to it when making an outbound response or REST API Trigger call, to determine if they responded previously.
It is important to make sure you have customer opt-in before initiating an outbound SMS.

You could use the Messages Resource and include the optional parameter of the incoming message from number. Check the response back from the API call and look for the body property.
If they've messaged you in the past you'll get a response and you'll see what they messaged you.
You could do this using a Twilio function and the run function widget or just use the http get widget and then use a split based on widget to make a branch based upon the returned JSON.

Related

Twilio: Webhook not calling specified URL on phone number

Setting up to respond to SMS replies. I've gone to my Active Numbers page, selected the number (I only have one), gone to the Messaging Service section (again only one service) and in "A message comes in", I've specified the URL of one of our HTTP Handlers. It's a .Net Core handler that we use all the time. It will try to process anything sent to its URL:
https://ourserver/lmw/core/filemanager?SC=SMS
I send an SMS message to my personal number, reply "Help", and send that. Nothing hits that URL. I have it in the debugger and it catches anything I send it. It just doesn't get hit by the reply to the SMS message.
What am I doing wrong?.. or did I misunderstand how this works?
EDIT:
I found an "Integration" section in the Messaging Service. It was set to "Defer to sender’s webhook"... which sounds right but I changed it to "Send a webhook -- Invoke an HTTP webhook for all incoming messages"... which sounds like the same thing. Anyway, it didn't change a thing. I'm still not receiving a post on the http handler.
Please note that "Help" is a special keyword when using messaging services.
According to the Twilio Help Center:
Twilio does not forward HELP/INFO messages to your incoming message webhook by default. However, if you use Advanced Opt-Out for Messaging Services, Twilio does forward HELP/INFO requests to your inbound webhook.
This is not a good answer but I wanted to close this out. I started over and released my phone number and bought a new one. I went to Active Numbers and selected the new phone. In "A message comes in", I put my webhook url in both primary and primary fails and saved that.
I then went to Messaging, Services, and selected my service. In Integration, I clicked "Defer to sender's webhook" and then put the handler url in "Callback URL" and saved that.
I went to compliance and the first two were done but 3. Campaign Use Case was incomplete. I completed that.
In Opt-out management, I edited that and put in some of my own text.
After doing all this, I replied to the message and got a response in the handler. Not sure which one of these was the problem but doing it all over seemed to work. Sorry I can't provide a better insight.

Twilio Messaging - Correlating SID

We use twilio for sending message.
We are not sure how to correlate the response with the message we send. We might send multiple messages to the same Mobile. But, not sure how to correlate response with the messages we sent as the SID's are different.
Is there anyway to relate the response with the message.
Thanks
No, SMS doesn't work like that.
I you send me 5 text messages from your cellphone and then I reply to one you have no way of telling which one I'm replying to.
It's not a Twilio limitation, the SMS standard has no provision to track replies to individual messages
As an afterthought I came up with a hacky solution to this. It's a bit involved so I guess it depends how much you want the functionality.
This works for me using Chrome beta on Android 7.0, YMMV.
Create a php script with the following code and put it on your webserver:
<?php
// increase last digit as necessary to suit string length of your variable
$smsid = substr($_SERVER["QUERY_STRING"],0,1);
// Query database for SMS id, record timestamp of request, optionally return text to be included at the beginning of the SMS reply
$msg= urlencode($databaseResult);
// Remove <?body=$msg> if you just want the link to create a blank reply. Change the phone number to your incoming Twilio number.
header( "Location: sms:+1555444333?body=$msg" )
Now sign up for a URL shortening service which passes URL parameters and create a shortened URL which points to your php script. I used tr.im.
Depending upon your volume of SMS you will have to adjust the length of your variable, but unless you spam people to death I'm going to assume a single character will be enough to identify a unique text.
Using the example tr.im/SMS as your shortened url, you append a variable to the end like so tr.im/SMS?A and put the link in your outgoing SMS. When the user clicks the link your server redirect will open the SMS app on their phone and create a text to your number. If you have included the "?body=$msg" in your php above the new message will have your text at the start.
Personally I probably wouldn't bother adding text, they might delete it before they send it anyway and it's just likely to confuse people. If you log the request variables and timestamps to your database you should be able to tie them together with the phone number as most people will send you their reply within a couple of minutes of the server request. You can also increase the length of your custom URL variable if you struggle to correlate messages. Recycle variables once you have linked a reply etc...
Finally change your Twilio configuration so your outgoing SMS present the company name instead of your Twilio number as the sender. Users cannot directly reply to messages if the sender isn't a number, so they will have to use your link.
Generate a sequential identifier for each message and append it to your link. Save the identifier to your database along with the corresponding message Sid from Twilio and the number you sent it to so you can match them up later.
Append "Click tr.im/SMS?$ to reply" to outgoing SMS, where $ is your variable.
Profit.

Twilio Task Router , Reservation Changing Status

Following the tutorials to creation of a task router (Workspace,queue,worker,task) and task creation via a Phone Call.
I am able to successfully land the call and create the task via my node.js app.
After adding the Agent UI via tutorial #
Agent UI Add Project
Here is the application flow:
Customer calls Twilio number
Twilio Voice Posts to a Node.js Rest API
Twilio Voice Posts to a Node.js Rest API
Twiml generated and user gets Prompts
User chooses an option
Response is Posted to a Node.js API and task is created
The above steps are success
On the client
Agent launches the node.js app with taskrouter.min.js and agent.js as provided in the sample above.
Customer gets the default hold noise, on the agent browser a series of events "reservation created, update and reservation cancels" are observed. Posting the console logs towards the end.
Observation 1, customer gets the default Hold noise confirms that Task is created successfully via the App. Task also seen on the Twilio Admin GUI
Observation 2, Getting a sequence of Reservation,Update,Cancel events multiple times.Also Observed that the dateCreated, dateUpdated and dateStatusChangedare year1970 , 1970-01-17T17:52:39.413Z.
Any pointers would be greatly appreciated.
[Edit:]
I do see similar issues with the PHP Sample code as well. Found that the Date is not an issue.
[Edit:]
Reached out to Twilio Support, hoping to hear from them, no luck so far
[RESOLVED]
Heard back from twilio support, thanks twilio. Issue was with the Assignment Callback URL on the Workflow. My API was /Get. Changed it from Get to Post, to make it work. As the assignment URL was not reachable (via POST), task router was trying to cancel the reservation.
Twilio employee here.
This is result of TaskRouter being able to hit your AssignmentCallbackUrl with an HTTP POST request. We've noticed that on your Account there's this notification message:
Cannot POST /assignment
Please enable POST for your AssignmentCallback endpoint.
TaskRouter will actively cancel the reservation if it cannot hit your AssignmentCallbackUrl or there is an error when issuing an Assignment Instruction.
The several updates in the console are due to the fact that TaskRouter cancels the reservation due to not hitting the AssignmentCallbackUrl, moving the Worker back to the previous state (Available), and then trying to assign the Task again, and thus generating another Reservation for the Worker for the same Task (repeat 15x until the Max Task Assignment is hit).
Heard back from twilio support, thanks twilio. Issue was with the Assignment Callback URL on the Workflow. My API was /Get. Changed it from Get to Post, to make it work. As the assignment URL was not reachable (via POST), task router was trying to cancel the reservation.

What if the Twilio Browser Client user is afk? How to change a Ready device to Not Ready?

I must be missing something.
I've successfully set my web page so that the browser is ready to receive incoming calls using the code from the Twilio QuickStart guides, but I wanted to give my user the ability to set their status to "Not Ready to Take Calls" if they're afk for example.
Is there a way to do this?
I've looked at the documentation and the closest thing I can find is:
Twilio.Device.disconnectAll();
But disconnectAll doesn't prevent incoming calls.
I'm wanting something like the ability to set Presence but there's only a method to register a callback when a Client's Presence changes:
Twilio.Device.presence(function(presenceEvent) {...});
And Presence currently only changes when a Client is on another call. I want the Client to be able to set Presence to a state that means incoming calls aren't directed to it.

How do I use Twilio to receive text messages from users and reply to that text with a message?

1.) User sends a text message to a designated Twilio phone number
2.) Application receives this message and parses it for actionable data
3.) Application replies to sender with a text message delivering the requested information
How the heck do I do this with rails?!
Assuming your business logic doesn't take that long to execute, it's pretty simple to process a text and send a response. Here are the core steps:
Grab the twilio-ruby helper library.
Point your SMS Url to the Rails controller/action you'd like to invoke
Process the incoming request & execute your business logic
Instead of returning HTML, return TwiML
Here's a link to a simple app that does just this:
https://github.com/crabasa/twilio-rails-demo
Update: I've written two detailed blog posts on integration Twilio into a Rails 4.x app: Part 1 and Part 2.

Resources