-
-
Save SylarRuby/00bad4dfddc2b620856dbb8fc6ab1ee3 to your computer and use it in GitHub Desktop.
Catch error for Facebook Messenger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NotificationWorker | |
include Sidekiq::Worker | |
include Facebook::Messenger | |
def perform | |
token = ENV["ACCESS_TOKEN"] | |
sender_id = '12345' | |
text = # "Your reminder to brush your teeth is in 5 mins" | |
standard_text(sender_id, text, token) | |
end | |
def standard_text(sender_id, text, token) | |
begin | |
# This will still fire no matter what! | |
Bot.deliver( | |
{ | |
recipient: { | |
id: sender_id | |
}, | |
message: { | |
text: text | |
} | |
}, access_token: token | |
) | |
rescue => e | |
# User not receiving message at this time | |
# Get their email or phone number, if available, and send an email/message | |
puts e.inspect #=> Facebook Error | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment