Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com> Co-authored-by: Manoj <manojmj92@gmail.com> Co-authored-by: Nithin <webofnithin@gmail.com>
This commit is contained in:
44
app/controllers/api/v1/facebook_indicators_controller.rb
Normal file
44
app/controllers/api/v1/facebook_indicators_controller.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
class Api::V1::FacebookIndicatorsController < Api::BaseController
|
||||
|
||||
before_action :set_access_token
|
||||
around_filter :handle_with_exception
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user