Twilio sms reply feature - php

I've created a system based on cron job which generates new tasks for user. When new task is generated cron file sends a sms to user using twilio sms api. Now I want make something like when user reply to that sms with word "Done" that task associated with sms will be completed in my database.
I've set reply URL in twilio account. And everything is working fine. My point is how can I complete that task in database. Is there any feature exist in twilio that can help me to send extra parameter as task id, so that I can fetch that id from reply and update the status of task.

Twilio developer evangelist here.
There's no way in SMS to reply to a specific message (try it yourself in your SMS app on your phone), so there's no ID that you can pass around secretly within conversations.
There are a few ways you can work around this.
If the user is sent only one task at a time, then you can record what their current task is and when you receive the message saying "done" tick that one off and send them the next task.
You could send them a task ID within the message, and tell them to include that ID when they respond to say they are done. You could then parse the ID out of the message and mark it as done in your database.
Or, and this might be too far, you could use a pool of numbers to send tasks out such that each live task for a user has a unique number the user responds to. Then you can look up the task based on the user and the number they replied to. Then you can free up the number for a new task.
Let me know if this helps at all.

Related

Back and forth SMS text messages replies in Twilio

I am working on a twilio sms API.
I have many users on my website and all of these users have a particular form on their profile page.
when a visitor goes to particular user profile and fill out the form.
then i send an automatic message from Twilio to the visitor, which basically says "Thanks for filling my form i will be in touch with you shortly"
Now here comes the challenging part where i am lost.
When the visitor tries to reply to that message. i want that message reply to be received to the particular user whose profile form was filled up. so every particular user should be able to receive their own text messages and start back and forth conversation on SMS.
It will be a dynamic reply from both users and visitor's end.
You can look into Twilio Conversations. You can find more information on conversations at the links below. Basically, you create a conversation and add participants to that conversation. Participants can be either SMS, MMS, WhatsApp, or Twilio Chat. Participants are assigned a Twilio Proxy Number with which they communicate through Twilio on.
Introducing Twilio Conversations: Now, every message becomes an invitation for a conversation
Using Twilio Conversations (Using Conversation You Tube Video - Signal 2019)
How to Use Twilio Conversations API (Twilio Chat to SMS tutorial)
Twilio Conversations Quickstart
The Conversations API Overview
Since users interact with you first through SMS and you want to continue the conversation with them through SMS.
This is the steps I would take
Receive and Reply to SMS Message. The example is in PHP but you can find an example in other languages.
You can reply with users SMS with Create a SMS Conversation using HTTP cookies with Webhooks

Track conversation chain from different server sessions to one number

I'm creating an app which will allow all users to initiate conversation with page owner using Chat-to-SMS service.
Problem is that I'm not sure how to track conversations since there would be one conversation chain from SMS Provider <-> page owner. When owner clicks reply, it needs to know which session user it needs to send the message to.
Basically, I need to do opposite what is being explained here: https://www.twilio.com/docs/quickstart/php/sms/tracking-conversations
How should I accomplish this? I can't quite wrap my head around this.
Twilio developer evangelist here.
If you are sending all the chat messages to just one SMS number then there is no easy way to tie replies back to the original message. (As a quick experiment, if you open an SMS conversation in your own phone and try to reply to any message that wasn't the latest one, you'll see it's not possible.)
There are workarounds though.
You could, when forwarding the message, generate an ID for it. Then get your page owner to include that ID when responding to that message, that way you can route the message back to the original sender and strip out the ID.
Alternatively, when replying you could always respond to the last message that came in. This relies on there not being much traffic, allowing the page owner to respond before the next message arrives. This is error prone though.
Another alternative is purchasing a new number for each new conversation. You could expire the number after a predetermined amount of time. This is made much easier with Twilio Proxy, which was announced recently and is currently in preview.
Let me know if that helps at all.

How can I set a queue status for Twilio SMS messages via PHP?

I've integrated Twilio for a client, but I need to incorporate their hours of operation. I know the sms messages have statuses, but how can I control the status when the message is created? I need the message to be created, but IF it's outside of hours of operation to NOT send the text... so put it in a queue... then when hours open again, send the text.
I see how I can query a sent message and see the status... but I want to specify the status and make sure it doesn't get sent until I specify when.
Please let me know how I can accomplish this. Thanks!
Megan from Twilio.
This is something you'll have to build into your application logic.
There are plenty of approaches you could take here such as scheduling a cron job or using a worker like Iron.io as seen in this post.
I hope this info helps.

PHP API track Twilio Responses

i'm working on an web app that has a message thread within and each time a new message is sent to a person a SMS is sent to that person, so what we want to do is to include the person's response to that SMS, lets say A sends a message to B, B receives both an email and a SMS, if B responses to A via the phone we need to be able to add that response to the thread. Is there a way to add additional information when you send a message using the API?
The sending SMS code looks like this:
$client = new Services_Twilio($accountSID,$authToken);
$sms = $client->account->messages->sendMessage("TwilioNumber",$toNumber,$message);
So, is there a way in which i could add some type of information to track this SMS thread, so when i get the response to the Request URL i could actually know that this message is being sent from B as a response from the message sent from A.
Thanks in advance.
Twilio evangelist here.
Unfortunately SMS does not have the idea of "meta-data" so there is nothing you can include that would tell you a message is in "response" to another message, but there are some solutions here.
You could create a convention of commands that are included in the actual body of the text message that tell you the message is ins response to a specific thread. But thats not super user friendly.
You're best bet is probably going to using multiple phone numbers and phone number tracking.
For example, when A sends the message to B you'll need to store both of their phone numbers along with the Twilio phone number that is receiving and relaying those messages. This allows you to map the two users together in a "thread" even though they are not directly texting each other.
But what happens when A wants to have seperate thread with both B and C? With a single Twilio phone number how do you know what thread to route their message to? The simplest way to allow this is to have multiple phone numbers. To send a message to B, A sends to 555-555-5555, to send a message to C, A sends to 555-555-6666. In this scenario you might think about buying a pool of numbers that you can draw from and recycle so you don't have to continuously buy new numbers.
Hope that helps.

Trying to make an SMS Reminder Application

I am working on a web-application to make an SMS Reminder service, which takes various inputs from the user, like the user's name, his number, and the time he wants the reminder. The reminder is then sent through an SMS. I have the SMS Gateway part figured out for which I am using Zeep Mobile's API. I wanted to know how I can send an SMS on the time input by the user.
The database would have the user-id and the time, and I need to get my application to send an sms at the time. Any tutorials on similar lines would be great help.
Thanks in advance
Let's say your reminder interval is 1 minute and you are deploying on Linux.
1) Set up a cron-job to check your database every minute for possible reminders
2) If there are reminders to be sent, execute your sending script.
3) Mark sent reminders with a status (or similar) so you don't send them again.
Depending on what server your application is deployed, you would need to run some kind of service that would run continuously and send SMS whenever one is due.
One note though, since repeated database access is costly, you may like to load up Reminders that would need to be sent in a short time. The database should be accesses periodically with a reasonable time interval.

Categories