Refactor Conversation, Message API calls, store

This commit is contained in:
Pranav Raj Sreepuram
2019-10-27 19:01:59 +05:30
parent c21c839dca
commit 170f8716c5
13 changed files with 215 additions and 402 deletions

View File

@@ -3,22 +3,26 @@ class Api::V1::FacebookIndicatorsController < Api::BaseController
around_action :handle_with_exception
def mark_seen
Facebook::Messenger::Bot.deliver(payload('mark_seen'), access_token: @access_token)
fb_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)
fb_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)
fb_bot.deliver(payload('typing_off'), access_token: @access_token)
head :ok
end
private
def fb_bot
::Facebook::Messenger::Bot
end
def handle_with_exception
yield
rescue Facebook::Messenger::Error => e
@@ -27,14 +31,24 @@ class Api::V1::FacebookIndicatorsController < Api::BaseController
def payload(action)
{
recipient: { id: params[:sender_id] },
recipient: { id: contact.source_id },
sender_action: action
}
end
def inbox
@inbox ||= current_account.inboxes.find(permitted_params[:inbox_id])
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
def contact
@contact ||= inbox.contact_inboxes.find_by!(contact_id: permitted_params[:contact_id])
end
def permitted_params
params.permit(:inbox_id, :contact_id)
end
end