3

I am building a rails application (based out of India) wherein I need to send sms to users whose bookings are confirmed. I am using a trial account on Twilio for this purpose. However, when I try to send sms, the status always shows as 'pending' and I don't receive the sms to my desired destination number. What could be the reason?

I have created a notification_controller with the below code:

class NotificationController < ApplicationController

  skip_before_action :verify_authenticity_token

  def notify
    client = Twilio::REST::Client.new 'my_account_SID', 'my_account_Token'
    message = client.account.messages.create from: 'twilio_number_assigned', to: 'my_number', body: 'Learning to send SMS you are.'
    render plain: message.status
  end

end

and made a POST request to /notifications/notify.

UPDATE:

In case another bulk sms provider service has worked for your rails app, feel free to share the related docs. Thanks!

Rahul Poddar
  • 343
  • 1
  • 4
  • 12
  • 1
    Just a note, in Twilio trial account you can send messages only to the number that you have confirmed in Twilio dashboard. If you didn't do so you'll need to add a number. Check your verified numbers at https://www.twilio.com/user/account/phone-numbers/verified. – rmagnum2002 Dec 16 '14 at 09:50
  • I am sending sms only to my verified number rmagnum2002 – Rahul Poddar Dec 16 '14 at 09:55

1 Answers1

2

Try to send it as hash, that's what Twilio suggest and that's how I used it in my app:

client = Twilio::REST::Client.new account_sid, auth_token 
client.account.messages.create({
    :from => 'twilio_number_assigned', 
    :to => 'my_number', 
    :body => 'Learning to send SMS you are.',  
})

Also you can test a message send request:

https://www.twilio.com/user/account/developer-tools/api-explorer/message-create

You'll fill in the needed fields and you'll get below the Request the code example you should use in your app.

About the Status of a message:

What you do in controller is returning current status of the message at the time of delivery, normally this will be as pending. You need to set up a callback that will be used by Twilio to notify you when the message was sent.

https://www.twilio.com/docs/api/rest/sending-sms

StatusCallback

A URL that Twilio will POST to when your message is processed. Twilio will POST the SmsSid as well as SmsStatus=sent or SmsStatus=failed.

Sending messages to Indian numbers

https://www.twilio.com/help/faq/sms/are-there-limitations-on-sending-sms-messages-to-indian-mobile-devices

  1. They cannot be sent to any phone number in India’s Do Not Call Registry

If you’ve been having trouble sending SMS messages to an Indian number, see if that number is registered on the National Do Not Call Registry.

If the owner of the phone number wishes to start receiving SMS messages from Twilio, they can update the DNC settings by following the instructions here.

Please note that the above limitations are regulations set up by Indian government.

rmagnum2002
  • 11,341
  • 8
  • 49
  • 86
  • Tried these as well...yet no results. Checked Twilio dashboard...it says there are total 10 sms in Sent API and 10 as undelivered...dont know the reason – Rahul Poddar Dec 16 '14 at 10:29
  • Also, I tried to deliver using the link that you shared (https://www.twilio.com/user/account/developer-tools/api-explorer/message-create). It says "This request costs money. You can find pricing information here". Does that mean I cant do a dry run using their trial account? – Rahul Poddar Dec 16 '14 at 10:45
  • I get the same message if I try to send message to a number I didn't verified. Double check your number, it has to start with `+` then `country code` and `number`. Anyway, I guess you just have to wait for a Twilio guy to see this question and answer to it. I tried to search in their help section and couldn't find anything helpful. – rmagnum2002 Dec 16 '14 at 11:39
  • 1
    One more article that might help, https://www.twilio.com/help/faq/sms/are-there-limitations-on-sending-sms-messages-to-indian-mobile-devices not sure if this is your case. – rmagnum2002 Dec 16 '14 at 11:58
  • I checked on Twilio....it says that my number has been blacklisted and hence the sms remains undelivered...I have posted this issue on Twilio support center, awaiting their response. No idea why they blacklisted my number :( – Rahul Poddar Dec 16 '14 at 13:25
  • 1
    I don't think is Twilio who blacklisted it, it should be your operator that in order to filter spam messages they don't allow any operator to send promotional sms's, and that's what a Twilio message is - a promotion message. Read the link I posted above, it says everything about it. Also if your app will send messages to India numbers you might want to look for a different service provider. – rmagnum2002 Dec 16 '14 at 13:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67077/discussion-between-sweta-lal-and-rmagnum2002). – Rahul Poddar Dec 17 '14 at 05:06