Skip to content

Instantly share code, notes, and snippets.

@SylarRuby
Created March 13, 2017 06:52
Show Gist options
  • Save SylarRuby/00bad4dfddc2b620856dbb8fc6ab1ee3 to your computer and use it in GitHub Desktop.
Save SylarRuby/00bad4dfddc2b620856dbb8fc6ab1ee3 to your computer and use it in GitHub Desktop.
Catch error for Facebook Messenger
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