Back and forth SMS text messages replies in Twilio - php

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

Related

Twilio sms reply feature

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.

How to manage sms and reply from webapp through twilio

I'm creating a messaging web application with laravel 5.1 and twilio and i'm using laravel-twilio package.
Settings and configuration already done in twilio dashboard
In Programmable SMS section i'hv created a messaging service with copilot which includes a single phone number ((xxx) xxx-xxx).
Given a Inbound request url.
My laravel application code
I have simple user to user messaging where both user are online where nothing to do with twilio. But suppose one of the user is offline and another one is online and the online user send a chat message to offline user then i have to notify the the offline user through an sms to this user's phone number via twilo.
public static function notifyOfflineUser($user,$reply_text){
$message = "Mysite: ".$user->user_from->firstname.", '".strip_tags($reply_text)."' Reply via mysite ".url('general-message')." or SMS";
if($user->profile->mobile) {
try {
\Twilio::message($user->profile->mobile, $message);
} catch (\Exception $e) {
}
}
}
It's sending a sms to the user from the twilio phone number.
Where the user can reply to this message form his/her phone to this number.
And if the reply succeded i have to add the message to the online user's message board.
//Inbound request url routed to this url with From number, body and other data.
public function smsReply(Request $request){
$user_id_to = Profile::where('mobile', $request->get('From'))->first(['user_id'])->user_id;
$body = $request->get('Body');
$user_id_from = Message::where('user_id_to', $user_id_to)->orderBy('id', 'desc')->first()->user_id_from;
//dd($request->all());
$message = new Message();
$message->user_id_from = $user_id_to;
$message->user_id_to = $user_id_from;
$message->message = $body;
$message->save();
return response()->json(true);
}
Now if multiple online user send chat message to this offline user, offline user will get miltiple sms from the same twilio number and those all sms are coming in a same stack, that mean it's not coming in different sms if he/she reply to the sms it will send to the same number, and all online user will get same message added in their message board.
Now here is my question..
Is there anything else need form twilio like multiple number, short codes, tollfree or i have to do the trick with my laravel code so i can send each sms to the offline user's phone as a different sms so i can distinguish them from inbound request url ? Feel free to ask me if more information needed.
Twilio developer evangelist here.
In order to be able to deal with multiple conversations like that, you're going to need multiple numbers. That way a number can represent the relationship between two users and you can tell what the user is responding to.
I recommend you check out this tutorial on building SMS conversations using multiple numbers with Laravel for more information.

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.

How can I Send message to WhatsApp Group and Sync contacts using WhatsAPI?

OK, I working on an application trying to send invitations to user contacts over WhatsApp so scenario will be as follow.
User will open invite screen.
Screen open filled with his contacts
Each contact marked if he is whatsapp user or not (Is it Applicable)
when user select X from his contacts to send them invitations
Client will send contacts details to the server
Server will send to those contacts a whatsapp message (Is it applicable)
Note: regarding password what I understand is that password different for each user so how can I get the whatsapp password for each user using my application.
Thanks
First of all, getting WhatsApp password of each of your users is not feasible I think.
Because while registering WhatsApp with YOUR app, user's official WhatsApp will fail to authenticate.
If you want to send just an invite or message you can use Intent. http://www.whatsapp.com/faq/en/android/28000012
Now back to WhatsAPI,
You can send messages to group just like an ordinary message
WhatsProt::sendMessage($groupJID,$message);
To get the list of groups, you can use the
WhatsProt::sendGetGroups();
You have to bind this to an event manager like this:
WhatsProt::eventManager()->bind("onGetGroups", "onGetGroups");
WhatsProt::sendGetGroups();
//event manager call-back function.
function onGetGroups($phone,$groups)
{
var_dump($groups);
}

Send Message to users inbox using PHP based facebook apps

I have created an application which can post to users wall or even send emails to selected users, what I have not been able to come up with is the functionality to let an application send a message to users facebook inbox, I have googled it and found that applications are not allowed to send messages to users inbox however there's this product called rockmelt browser which does the same thing.
There's has to be some way which allows sending messages to users inbox.
Can somebody guide me on this?
It appears that you cannot send a message to a user's inbox. The closest thing may be this http://developers.facebook.com/docs/reference/rest/livemessage.send/. It allows you to send a live message to a particular user's browser.
Hope this helps.
If you are sending the message from your application user to one of their Facebook friends, you can use a Request, which will show up in the notification area. When the user clicks on the notification, they'll be taken to your App Canvas where you can show them the full message and any other app interactions you want.

Categories