Twilio checks if the phone number is blacklisted

I am currently integrating into twilio rest api and you need to check the user's phone number to determine if this user has been blacklisted or not. I have little experience with this api and combing documentation, and Google did not understand anything.

In our application, we will have a notification center, and if the user is blacklisted, I do not want to give them the opportunity to include their SMS notifications. Potentially, the user could receive SMS notifications, but twilio would block any messages. I know that it is possible to get a status code from twilio when it is blacklisted in an SMS queue ( https://www.twilio.com/docs/api/rest/message ). However, I will not send messages on the notification screen and you need a direct way (if at all possible) to check twilio to determine if the number is blacklisted. Any help is much appreciated. Let me know if more info helps.

+5
source share
1 answer

Megan from Twilio.

I would be interested to know if you have ever tried on your own. But I wanted to point out to others in a similar situation, how you could capture a blacklist error, and then do whatever you might need.

In Ruby, it will 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::RequestError => e if e.code == 21610 # User is blacklisted # Store info however you choose puts e.message end end 

We check for a blacklist using the code '21610'. Additional error information can be found on the help page .

Hope this helps!

+8
source

Source: https://habr.com/ru/post/1200072/


All Articles