Chore: Send browser language in webwidget events (#952)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -2,12 +2,19 @@ class Api::V1::Widget::EventsController < Api::V1::Widget::BaseController
|
||||
include Events::Types
|
||||
|
||||
def create
|
||||
Rails.configuration.dispatcher.dispatch(permitted_params[:name], Time.zone.now, contact_inbox: @contact_inbox)
|
||||
Rails.configuration.dispatcher.dispatch(permitted_params[:name], Time.zone.now, contact_inbox: @contact_inbox, event_info: event_info)
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def event_info
|
||||
{
|
||||
widget_language: params[:locale],
|
||||
browser_language: browser.accept_language.first&.code
|
||||
}
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:name, :website_token)
|
||||
end
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import Vue from 'vue';
|
||||
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
||||
|
||||
const sendMessage = content => {
|
||||
const locale = Vue.config.lang;
|
||||
const refererURL = window.refererURL || '';
|
||||
let search = window.location.search;
|
||||
if (search) {
|
||||
search = `${search}&locale=${locale}`;
|
||||
} else {
|
||||
search = `?locale=${locale}`;
|
||||
}
|
||||
|
||||
const search = buildSearchParamsWithLocale(window.location.search);
|
||||
return {
|
||||
url: `/api/v1/widget/messages${search}`,
|
||||
params: {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { API } from 'widget/helpers/axios';
|
||||
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
||||
|
||||
export default {
|
||||
create(name) {
|
||||
return API.post(`/api/v1/widget/events${window.location.search}`, { name });
|
||||
const search = buildSearchParamsWithLocale(window.location.search);
|
||||
return API.post(`/api/v1/widget/events${search}`, { name });
|
||||
},
|
||||
};
|
||||
|
||||
16
app/javascript/widget/helpers/specs/urlParamsHelper.spec.js
Normal file
16
app/javascript/widget/helpers/specs/urlParamsHelper.spec.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { buildSearchParamsWithLocale } from '../urlParamsHelper';
|
||||
|
||||
jest.mock('vue', () => ({
|
||||
config: {
|
||||
lang: 'el',
|
||||
},
|
||||
}));
|
||||
|
||||
describe('#buildSearchParamsWithLocale', () => {
|
||||
it('returns correct search params', () => {
|
||||
expect(buildSearchParamsWithLocale('?test=1234')).toEqual(
|
||||
'?test=1234&locale=el'
|
||||
);
|
||||
expect(buildSearchParamsWithLocale('')).toEqual('?locale=el');
|
||||
});
|
||||
});
|
||||
10
app/javascript/widget/helpers/urlParamsHelper.js
Normal file
10
app/javascript/widget/helpers/urlParamsHelper.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import Vue from 'vue';
|
||||
export const buildSearchParamsWithLocale = search => {
|
||||
const locale = Vue.config.lang;
|
||||
if (search) {
|
||||
search = `${search}&locale=${locale}`;
|
||||
} else {
|
||||
search = `?locale=${locale}`;
|
||||
}
|
||||
return search;
|
||||
};
|
||||
@@ -56,6 +56,7 @@ class AgentBotListener < BaseListener
|
||||
agent_bot = inbox.agent_bot_inbox.agent_bot
|
||||
|
||||
payload = contact_inbox.webhook_data.merge(event: __method__.to_s)
|
||||
payload[:event_info] = event.data[:event_info]
|
||||
AgentBotJob.perform_later(agent_bot.outgoing_url, payload)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,6 +38,7 @@ class WebhookListener < BaseListener
|
||||
inbox = contact_inbox.inbox
|
||||
|
||||
payload = contact_inbox.webhook_data.merge(event: __method__.to_s)
|
||||
payload[:event_info] = event.data[:event_info]
|
||||
deliver_webhook_payloads(payload, inbox)
|
||||
end
|
||||
|
||||
|
||||
@@ -107,10 +107,7 @@ class Conversation < ApplicationRecord
|
||||
end
|
||||
|
||||
def webhook_data
|
||||
{
|
||||
display_id: display_id,
|
||||
additional_attributes: additional_attributes
|
||||
}
|
||||
Conversations::EventDataPresenter.new(self).push_data
|
||||
end
|
||||
|
||||
def notifiable_assignee_change?
|
||||
|
||||
Reference in New Issue
Block a user