Twilio inbound messages - Not Shown - ruby-on-rails

I'm having a problem receiving Messages and i don't know where and what goes wrong.
Right now i received messages from the United States that are shown in the Inbound Twilio Dashboard and are accessible through the API.
e.g.:
<% #client.account.sms.messages.list({ from: "#{#contact.mobile}", }).each do |message| %>
Bur responses from other countries don't show up anywhere.
For Sending and receiving messages i use the format:
+1757*******
Has the format something to do with it ? What am i missing?
From Twilio Doc:
Phone numbers should be formatted with a '+' and country code e.g.,
+16175551212 (E.164 format). For 'to' numbers without a '+', Twilio will use the same country code as the 'from' number. Twilio will also
attempt to handle locally formatted numbers for that country code
(e.g. (415) 555-1212 for US, 07400123456 for GB). If you are sending
to a different country than the 'from' number, you must include a '+'
and the country code to ensure proper delivery.
After some serious Twilio Scanning i found the Answer - Read below

Twilio Evangelist here.
This could be a number of things. So first off, do the incoming messages show in your Message Logs on the Twilio Dashboard?
If they don't show up, then you make sure you have a URL set for number receiving them.
If they do show up, copy one of the numbers as shown in the logs and try this out in your app. It's a little tricky to be specific without more details, but I expect you should use the +<country><number> format as stated. So for US: +1415xxxx..., for the UK +447590xxxx...' and so on.
You could also try running this code:
<% #client.account.messages.list({to: your_twilio_number}).each do |message| %>
Display all the messages and check for the inbound messages there, then try again once you've double checked your contact.mobile formatting.
Hope this helps.

For everyone with the Same Issue.
When Setting up a Twilio account you receive a US Number, which works a little different from other Countries.
SMS Enabled Phone Numbers: Some are able to send SMS internationally and domestically, but others are only able to send and receive SMS domestically.
For the United States there is no Mobile, only Toll-Free and Local. With that, other carriers (Outside the US) wont even let your sms trough, thinking that the number on the other end is not a Mobile.
Basically, only US Numbers can send an SMS to a US Number, other countries can't.
So i bought a UK Number and everything is working now.

Related

Apple messages auto-call

have an interesting problem I need to solve, I was hoping if anyone could give me some sort of an idea.
For example, if I get a text from someone saying (string) “URGENT” on my iPhone, I want to call them immediately.
So say I get a message, it could be any message but if their message says “urgent”, I need to call them ASAP, even when my phone is turned off.
Is there a way to do this, using API or anything?? I have no idea!!
Example say I get a messages saying:
Number 042XXXXX sends me a text:
"Hi Name, I have some urgent work for you"
Number 1300 XXX XXX sends me a text:
"Urgent help needed"
Both of these messages would be read by iPhone and their respective numbers would be dialled urgently.
Is there such a way to do this/automate this??
Any advice would be appreciated!!
I have no idea what to do, I am blank!!
I think the problem you have needs an indirect solution because, as Paulw11 points out, Apple don't allow you to inspect the message directly.
It would be possible to make use of Twilio's Programmable SMS API to setup a special phone number that customers could send text messages to. Then you use the APIs of Twilio to read the messages and then send an Apple Push Notification message for those the had "urgent" in the message.
You could then write an iOS app which receives push notification messages and takes the actions you desire. For example, it could present a screen which could automatically dial the number in question.

Twilio SMS Webhooks and Group Text Messages

Is it possible to maintain both group text messages and single text messages with users and keep them separate? I understand there is no concept of a group message per se, but wanted to see if any recent advances in tech has made this possible with Twilio or other providers.
In short, I am creating a POC where a user inside an iOS App can send invoke an API call to my backend application. This application receives a phone number from someone's contact list, and then connects to Twilio to send the SMS message to that target user.
When the user replies, I was researching Twilio Web hooks to receive the message, and then save it in the database. The originating user, then, would be able to see the message on a screen.
I would guess that when a user responds to the twilio message, the only metadata that comes in is their message and phone number, so the "foreign key" is the phone number.. Thus when I save it in my database, I have their phone number and message.
This works up until someone decides to target two or more people in an SMS message using my API, and then target one of those people individually. For example they select me as a sole recipient, and then select me and someone else as a group text message.
In this case, how could my system/Twilio differentiate between if I was responding to the group message, or to the single message?
Any ideas or work arounds? Maybe another technology? Thanks!
I wanted to provide an answer to this in case anyone else was looking into this.
Essentially you pay 3 cents (0.03) per month per active user in each group. Basically you buy phone numbers for each group chat you need.
https://www.twilio.com/conversations/pricing
So if you're doing a million group chats obviously it can get costly, but for simple POCs this isn't the end of the world.
Enjoy!

Twilio SMS - what am I doing wrong?

So, I have WHMCS setup to use Twilio with a new module, however, I have managed to get as far as setting it up and having SMS messages go out to customers in Australia as I have an AUS number connected to my Twilio account.
The issue is that when say for an example a US customer signs up the SMS fails and says "cannot send sms", the logs aren't helpful for this Twilio newb.
Here is the example:
The process of sending SMS to the user phone number (+1310xxxxxxx) from the summary page has failed - Twilio (company name)
If I was to send a message to say Spain it seems to work, which is odd enough.
I also tried on a +34 and it sent. Also seems to work on the UK +44.
I have GEO options setup to work as they should within Twilio, though, the error message does not appear on my Twilio logs, simply internal.
Here is the module log.
I have only edited the text out to give you what is showing.
Request:
Array
(
[To] => +1310xxxxxxx
[Body] => test
[From] => Company name
)
Response
The 'To' phone number: +1310xxxxxxx, is not currently reachable using the 'From' phone number: Company name via SMS.
So presently SMS messages to the USA do not work, I cannot speak for every other country out there though, what can I do here or how would I set my Twilio account correctly to ensure my SMS messages are being delivered?
Many thanks.
Twilio developer evangelist here.
From what you're saying I think you're sending messages using an alphanumeric sender ID rather than a phone number?
If that's the case then you are getting rejected from the US because the US telephone system doesn't accept alphanumeric sender IDs (neither do some other countries, just not the ones you've tested). You can see the countries that do and don't support alphanumeric sender IDs in this table in our documentation.
To fix this you'll need a number to send the messages from in the US, I'd recommend getting a new US number for this.
Then you can either catch the error and retry using the number in place of the sender ID.
Or, for a more resilient method, take a look into Twilio Messaging Services that can do automatic failover to a number when sending with alphanumeric senders.
Let me know if this helps at all.

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 says I don't have permission to send to the region of my 'To' number

I am trying to send a simple SMS and have been doing so for over a year with my app. All of a sudden, on my staging and local environment (prod is fine), I keep getting this error:
Twilio::REST::RequestError: Permission to send an SMS has not been enabled for the region indicated by the 'To' number: '+13105551234'
Both numbers are local California numbers and I have the US enabled on my account. I changed the numbers to 5551234 for this SOF post but they are both valid numbers (the from number is my twilio number and the to number is my personal cell phone.
client.account.messages.create(body: 'hello', to: '+13105551234', from: '+15105551234')
What could be causing this error?
EDIT: I should mention it worked when I sent an SMS to my friend's phone and then when I tried a second time to his number, it gave me the same error.
So...turns out that after creating the Twilio number and activating everything. You have to come here, to pick the nations you want to text to.
#Visionwriter's answer is correct and exact answer.
URL is: https://www.twilio.com/user/account/settings/international/sms
I have also added a screenshot to breadcrumb on twilio console:

Resources