2020-01-09 07:36:40 +00:00
|
|
|
class Api::V1::Widget::BaseController < ApplicationController
|
2020-06-07 08:28:05 +00:00
|
|
|
before_action :set_web_widget
|
|
|
|
before_action :set_contact
|
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def conversation
|
2020-04-10 11:12:37 +00:00
|
|
|
@conversation ||= @contact_inbox.conversations.where(
|
2020-01-09 07:36:40 +00:00
|
|
|
inbox_id: auth_token_params[:inbox_id]
|
2020-04-10 11:12:37 +00:00
|
|
|
).last
|
2020-01-09 07:36:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def auth_token_params
|
|
|
|
@auth_token_params ||= ::Widget::TokenService.new(token: request.headers[header_name]).decode_token
|
|
|
|
end
|
|
|
|
|
|
|
|
def header_name
|
|
|
|
'X-Auth-Token'
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_web_widget
|
|
|
|
@web_widget = ::Channel::WebWidget.find_by!(website_token: permitted_params[:website_token])
|
|
|
|
@account = @web_widget.account
|
2020-05-06 08:08:36 +00:00
|
|
|
switch_locale @account
|
2020-01-09 07:36:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_contact
|
|
|
|
@contact_inbox = @web_widget.inbox.contact_inboxes.find_by(
|
|
|
|
source_id: auth_token_params[:source_id]
|
|
|
|
)
|
|
|
|
@contact = @contact_inbox.contact
|
|
|
|
end
|
2020-07-20 12:58:14 +00:00
|
|
|
|
|
|
|
def browser_params
|
|
|
|
{
|
|
|
|
browser_name: browser.name,
|
|
|
|
browser_version: browser.full_version,
|
|
|
|
device_name: browser.device.name,
|
|
|
|
platform_name: browser.platform.name,
|
|
|
|
platform_version: browser.platform.version
|
|
|
|
}
|
|
|
|
end
|
2020-01-09 07:36:40 +00:00
|
|
|
end
|