2019-08-14 09:48:44 +00:00
|
|
|
class Api::V1::FacebookIndicatorsController < Api::BaseController
|
|
|
|
|
|
|
|
before_action :set_access_token
|
2019-08-21 16:22:20 +00:00
|
|
|
around_action :handle_with_exception
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
def mark_seen
|
|
|
|
Facebook::Messenger::Bot.deliver(payload('mark_seen'), access_token: @access_token)
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def typing_on
|
|
|
|
Facebook::Messenger::Bot.deliver(payload('typing_on'), access_token: @access_token)
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def typing_off
|
|
|
|
Facebook::Messenger::Bot.deliver(payload('typing_off'), access_token: @access_token)
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def handle_with_exception
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
rescue Facebook::Messenger::Error => e
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def payload(action)
|
|
|
|
{
|
|
|
|
recipient: {id: params[:sender_id]},
|
|
|
|
sender_action: action
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_access_token
|
|
|
|
#have to cache this
|
|
|
|
inbox = current_account.inboxes.find(params[:inbox_id])
|
|
|
|
@access_token = inbox.channel.page_access_token
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|