I'm trying to integrate twilio into my rails app. I want to be able to tell if there are any error messages using a response returned from the 'get' method
Twilio's example has this
#notification = #client.account.notifications.get("NO5a7a84730f529f0a76b3e30c01315d1a")
that was on this page https://www.twilio.com/docs/api/rest/notification
Here is how I'm calling it in rails console
client = Twilio::REST::Client.new(ENV['twilio_account_sid'], ENV['twilio_auth_token'])
n = client.account.notifications.get("SMb6e3a5d4649e485ea9fa818ba84ec721")
n.message_text
And I get this error
Twilio::REST::RequestError: The requested resource /2010-04-01/Accounts/[my account]/Notifications/SMb6e3a5d4649e485ea9fa818ba84ec721.json was not found
That sid is a valid sid, and I confirmed it by looking in my logs.
So why can't I look up the message with this method?
Thanks
Twilio developer evangelist here.
I think the problem is that you are not looking up a notification in your example. The SID you are using is "SMb6e3a5d4649e485ea9fa818ba84ec721" which is for an SMS message (indicated by the "SM" at the front).
As you can see in the example from the docs, notification SIDs start with "NO".
You should be able to get hold of the message you are after using client.account.messages.get('SMb6e3a5d4649e485ea9fa818ba84ec721').
You can also find all the notifications to your account by calling client.account.notifications.list.
Hope this helps, let me know if you have any other questions.
Related
I would like to know if it's possible to use the user_name with Autopilot from the incoming post requests from Slack.
I've tried checking the documents but I'm not able to find any reference to handling incoming requests for Autopilot. Perhaps it isn't supported but does anyone know if it's possible?
Twilio developer evangelist here.
The documentation for handling incoming requests is here: https://www.twilio.com/docs/autopilot/actions/autopilot-request.
You should receive a UserIdentifier with the request which identifies the user in the platform the request came from. In the case of incoming phone calls or sms messages the identifier is the user's phone number. I haven't tested, but I assume that this would either be a user name from Slack, or an identifier you can use with the Slack API to find the user name.
Let me know if that helps at all.
I ended up being able to use the response data from Autopilot and found I was able to get the useridentifier from the json response as such:
user_name = request.form['UserIdentifier']
This has then allowed me to send direct messages via the incoming webhooks application in slack as using the above user name as the value for the channel key as follows.
payload={'text':"Ok, I'm working on it. I'll let you know when your request is ready.", "channel":user_name}
webhook_url= 'https://hooks.slack.com/services/<slack id>/<slack id>'
response = requests.post(
webhook_url, data=json.dumps(payload),
headers={'Content-Type': 'application/json'})
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
This isn't a question about why I got 11200 error. All I'm asking, is if twilio attempts the request again at a later time?
The documentation: https://www.twilio.com/docs/api/errors/11200 , doesn't mention anything about reattempting.
Twilio developer evangelist here.
Twilio doesn't retry any calls that fail. You would need to build it into your system so when you think something should have completed but it hasn't, you get it to trigger a Twilio request again.
Alternatively, if you have an unstable server, on your webhook, you can configure a fallback URL. You can also use that to let you know when Twilio tried to make a request and failed because your primary webhook was down.
Hope this help you
I am using twilio trial account for sending message and it generate SMS logs.
I want to remove all SMS logs from my trial account of twilio.
please help me.
You can use the PHP helper library to redact the body of a message, or delete the entire message resource:
$client = new Services_Twilio('AC123', '123');
$message = $client->account->messages->get("MM123");
$message->redact(); // Erases 'Body' field contents
$message->delete(); // Deletes entire message record
More info on deleting message can be found in our docs.
Hope that helps.
I have been trying to build a app that redirect a Twilio number to another phone number when a customer call Twilio number.
When callback URL does not return proper Twilml, it says "Application has failed" message on the call.
However, I do not want my customers hear that message even though there is a error.
Is there a way to turn that message off?
Thank you.
Twilio evangelist here.
There is no way to disable the error message, but you can set a Fallback URL on your phone number that Twilio will request in case the Voice Request URL fails.
You could set the Fallback URL to a simple static XML file hosted somewhere like Amazon or Dropbox, or use a service like twimlbin.com to host some backup TwiML for you.
I'm new to twilio and have the following situation. I want to send an SMS to someone for an appointment confirmation. They'll text back CONFIRM or CANCEL etc to the message.
Is there any way to pass an internal database id in the SMS to them and get it back in their response so i know what they're confirming or canceling? I'd rather it not be shown to the end user receiving the text.
Thanks!
Twilio evangelist here.
Unfortunately there isn't any way to transparently include metadata in an SMS and have that metadata returned to you when they reply, but there ways to address your scenario.
If you are sending the user a text message you already have their phone number and you can use that as a unique ID. When the user replies to your message, Twilio will as part of our HTTP request to your application, pass you the users phone number. You can use that number to locate them in your database and mark them as confirming or canceling.
Hope that helps.