Twilio sending messages and receiving back in cell phone - codeigniter

I am using Twilio rest API for Php and want to create an application to send and receive text messages.
We have many senders and every one wants to send and receive their messages. And every one want to receive text messages on their cell phone.
Is it possible to send text message to some one and we get our reply to our cell phone?
I am new in tiwlio so please can you guide me the procedure of sending and receiving text messages.
I have implemented sending part and not getting how to receive messages back on cell phone if someone reply.
Thanks

Twilio developer evangelist here.
When someone replies with a message to a Twilio phone number, Twilio will take the message and send it to a URL you define as an HTTP request. You can then decide what to do with the message.
You can, for example, forward the message on to another number. There is a restriction here in that you cannot forward the message and make it appear to have come from the original sender, you have to set the caller ID as one of your Twilio numbers. You can include the original sending number as part of the message though.
To do this, you would need to respond to the HTTP request with some TwiML. This is a subset of XML that tells Twilio what to do with the message. To forward the message including the original sender number, you would use the <Message> TwiML element from PHP like this:
<?php
$from = $_REQUEST['From'];
$body = $_REQUEST['Body'];
$forwarding_number = "THE NUMBER TO FORWARD THE MESSAGE TO";
// we'll forward from the Twilio number that received the message
$caller_id = $_REQUEST['To'];
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Message to="<?php echo $forwarding_number; ?>" from="<?php echo $caller_id; ?>">
Message from <?php echo $from; ?>: <?php echo $body; ?>
</Message>
</Response>
As I said though, there are limitations on this, the message will be sent to your users phone from your Twilio number. In reality, you likely want to be able to reply to the message again, so it's perhaps better to just send a notification to your users and build an application that can receive those messages and display them in a dashboard, using the API to respond to them.
I have started an example of this sort of app here on GitHub (it's built in Node.js, but might give you an idea).
Let me know if that helps at all.

Related

Including a full thread in the body of a reply from a bot

I created a bot that replies to mails. I use the Message.CreateReplyMessage(...) method.
The created message will contain the "Re: " prefix in it's subject but the body will not contain the previous messages on the thread, or at least the message sent to the bot.
Is there a way to have the body include the previous messages so it would look more like when we reply from outlook?
Thanks,
Uri
You have the full text of the message in the call to your bot. You can just append it to the end of your reply

Receive SMS on twillion phone number

I have attached call back URL in the Twilio account with the Twilio phone number. But still i am not getting a hit on the call back URL when sending SMS to twilio number. There is no history in Twilio about the message received, though it is showing sent from my mobile phone.
I did a work around to recieve messages.
In a background thread, I am continuously listening to see if the 'number of messages' changed:
def newMsgCame(self,client,old_len):
new_len = len(client.messages.list(to="<my twilio number>"))
if(new_len > old_len):
return True,new_len
return False,new_len
If yes, then I return the latest message:
def getMsg(self,client):
messages = client.messages.list(to="<my twilio number>")
if (len(messages) != 0):
return messages[0].body
return ""
This might fail in many scenarios though.

+CMS ERROR 41 on Telit Modem

I am a developer, working on "Telit" GE865-Quad using AT commands.
I am planning an application, witch sends SMS when certain condition occurs. When the application does not send SMS the modem is shut-down (Therefore every time I want to send SMS I have to turn on the modem). This application sends 3 SMS to different numbers one after the other.
The application is working just fine. The problem apear after a while (after sending certain amount of SMS), when I give the command to send SMS I get "+CMS ERROR 41" ("Temporary failure"). Once this message appear, every time I try to send SMS I get the same ERROR - It is like the SIM card is stuck. The only way I have found to get rid of this error is to enter the SIM card to my privet phone and send SMS.
I have spoken to "Telit" representative and he could not give a satisfying answer other then adding more delay between messages.
This is some of the relevant code :
(Turning on sequence) // From "Telit" GE865-Quad DataSheet
> #QSS: 3 //Before I start working with the modem i wait for this response with means the SIM is ready to use and the registration is to cellular network is complete*/
AT+CMGF=1 // Text Mode
OK
AT+CMGS=+xxxxxxxxxxxx // My number.
"This is the message i want to send" //Preparing the desired message require some coding But I think this is irrelevant to the subject.
//Delay for 3 secs//
And again : AT+CMGS=+xxxxxxxxxxxx // My number.
"This is the message I want to send"
//Delay for 3 secs//
(The same thing one more time)
The questions are:
Why does it happen, what am I doing wrong??
How can I unblock the SIM? What does the phone do so I can keep sending SMS?
The purpose is the keep sending SMS automatically.
This is the first time I publish a message in this website so if something is unclear please let me know. :)
Thanks for all the helpers.
Itay.
today i encountered this +CMS ERROR: 41 error, many times.
There was about 40 unread messages in the receiving modem.
After i deleted all received messages error disappeared.
I think may be operator is protecting customers from spam.
Dmitri
It is due Either SMS service on your SIM is not available or your SMS subscription is expired.

How would I design this scenario in Twilio?

I'm working on a YRS 2013 project and would like to use Twilio. I already have a Twilio account set up with over $100 worth of funds on it. I am working on a project which uses an external API and finds events near a location and date. The project is written in Ruby using Sinatra (which is going to be deployed to Heroku).
I am wondering whether you guys could guide me on how to approach this scenario: a user texts to the number of my Twilio account (the message would contain the location and date data), we process the body of that sms, and send back the results to the number that asked for them. I'm not sure where to start; for example if Twilio would handle some of that task or I would just use Twilio's API and do checking for smss and returning the results. I thinking about not using a database.
Could you guide me on how to approach this task?
I need to present the project on Friday; so I'm on a tight deadline! Thanks for our help.
They have some great documentation on how to do most of this.
When you receive a text you should parse it into the format you need
Put it into your existing project and when it returns the event or events in the area you need to check how long the string is due to a constraint that twilio has of restricting messages to 160 characters or less.
Ensure that you split the message elegantly and not in the middle of an event. If you were returned "Boston Celtics Game", "The Nut Cracker Play". you want to make sure that if both events cannot be put in one message that the first message says "Boston Celtics Game, Another text coming in 1 second" Or something similar.
In order to receive a text message from a mobile device, you'll have to expose an endpoint that is reachable by Twilio. Here is an example
class ReceiveTextController < ActionController
def index
# let's pretend that we've mapped this action to
# http://localhost:3000/sms in the routes.rb file
message_body = params["Body"]
from_number = params["From"]
SMSLogger.log_text_message from_number, message_body
end
end
In this example, the index action receives a POST from Twilio. It grabs the message body, and the phone number of the sender and logs it. Retrieving the information from the Twilio POST is as simple as looking at the params hash
{
"AccountSid"=>"asdf876a87f87a6sdf876876asd8f76a8sdf595asdD",
"Body"=> body,
"ToZip"=>"94949",
"FromState"=>"MI",
"ToCity"=>"NOVATO",
"SmsSid"=>"asd8676585a78sd5f548a64sd4f64a467sg4g858",
"ToState"=>"CA",
"To"=>"5555992673",
"ToCountry"=>"US",
"FromCountry"=>"US",
"SmsMessageSid"=>"hjk87h9j8k79hj8k7h97j7k9hj8k7",
"ApiVersion"=>"2008-08-01",
"FromCity"=>"GRAND RAPIDS",
"SmsStatus"=>"received",
"From"=>"5555992673",
"FromZip"=>"49507"
}
Source

How Can I Use xmpp4r To Detect The Online/Offline Status Of A Given Jabber ID?

What is the proper xmpp4r way to know if a given contact is online before sending them a message?
Can you post sample xmpp4r code for doing this?
Here is my use case:
If contact online, send :normal message
Else, email contact
Here are things I have working code for:
Send messages of various types
Get a roster/contact list
Register a call back to detect changes in presence
However, I can't find a place that directly addresses a work flow like this:
Loop through each JID in your roster
If jid.is_online? == true, send IM
Else, send email
I've read that you should send a JID a message of type :headline and if that fails, you know the user is offline. In my tests, if the user is ONLINE, they'll receive a message of type headline. This is suboptimal, as users should only receive messages to read, not noise to determine online status.
I've read that on sign on, all of your contacts will bounce a presence status back at you, and that status is the sole indication that they are online - assuming that there isn't a disconnect or presence change you've yet to receive. So you should register a presence call back, record the initial users who ping you back, and then add or remove from the list based on your running roster presence callback.
If this is truly the way to do it:
Can I get some example code of how to collect all the "I'm here" presence confirmations on sign on via xmpp4r?
Why, oh why, was xmpp designed this way and why is this better than offering an "is_online_and_available" method?
So the answer here is adding a message call back and checking inside the block for the type:
m = Message.new(to, body)
cl.send(m)
cl.add_message_callback do |m|
if m.type == :error
puts "type: #{m.type}"
else
puts "not an error"
end
end
This requires threading as you have to be listening for the response.

Resources