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!
Try to send it as hash, that's what Twilio suggest and that's how I used it in my app:
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
Sending messages to Indian numbers
https://www.twilio.com/help/faq/sms/are-there-limitations-on-sending-sms-messages-to-indian-mobile-devices
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.