Twilio check if phone number has been blacklisted

旧城冷巷雨未停 提交于 2019-12-08 17:12:06

问题


I am currently integrating into the twilio rest api and need to perform a check on a users phone number to determine if that user has blacklisted themselves or not. I have little experience with this api and scouring through the documentation and google has turned up nothing.

In our application we are going to have a notification center and if the user has blacklisted themselves I do not want to give them the ability to turn on their SMS notifications. Potentially a user could have SMS notifications on but twilio would block any messages. I know there is the ability to get a status code back from twilio when an SMS is queued that shows the user is blacklisted (https://www.twilio.com/docs/api/rest/message). However, I will not be sending messages on the notifications screen and need a direct way (if at all possible) to check twilio to determine if a number is blacklisted. Any help is much appreciated. Let me know if anymore information will be of help.


回答1:


Megan from Twilio.

I'd be curious to see if you ever tried your own workaround. But I wanted to note for others in a similar situation how you could grab the blacklist error and then do whatever you may want with it.

In Ruby it would look something like this:

require 'rubygems'
require 'twilio-ruby'

account_sid = 'YOUR_ACCOUNT_SID'
auth_token = 'YOUR_AUTH_TOKEN'

@client = Twilio::REST::Client.new account_sid, auth_token

begin
  @message = @client.messages.create(
    from: 'TWILIO_NUMBER',
    to: 'USER_NUMBER',
    body: 'Howdy!'
  )
rescue Twilio::REST::RestError => e
  if e.code == 21610
    # User is blacklisted
    # Store info however you choose
    puts e.message
  end
end

We check for blacklisting specifically using the code '21610'. For more information about errors you can visit the reference page.

Hope this helps!



来源:https://stackoverflow.com/questions/25254499/twilio-check-if-phone-number-has-been-blacklisted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!