feat: enable Dialogflow integration all inboxes except email (#3285)
Fixes #2461 Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
parent
d78cb67a2a
commit
cf5f6d5a74
8 changed files with 29 additions and 8 deletions
|
@ -59,9 +59,10 @@ export default {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
uiFlags: 'integrations/getUIFlags',
|
uiFlags: 'integrations/getUIFlags',
|
||||||
websiteInboxes: 'inboxes/getWebsiteInboxes',
|
websiteInboxes: 'inboxes/getWebsiteInboxes',
|
||||||
|
dialogFlowEnabledInboxes: 'inboxes/dialogFlowEnabledInboxes',
|
||||||
}),
|
}),
|
||||||
inboxes() {
|
inboxes() {
|
||||||
return this.websiteInboxes
|
return this.dialogFlowEnabledInboxes
|
||||||
.filter(inbox => {
|
.filter(inbox => {
|
||||||
if (!this.isIntegrationDialogflow) {
|
if (!this.isIntegrationDialogflow) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -78,6 +78,11 @@ export const getters = {
|
||||||
item => item.channel_type === INBOX_TYPES.TWILIO && item.medium === 'sms'
|
item => item.channel_type === INBOX_TYPES.TWILIO && item.medium === 'sms'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
dialogFlowEnabledInboxes($state) {
|
||||||
|
return $state.records.filter(
|
||||||
|
item => item.channel_type !== INBOX_TYPES.EMAIL
|
||||||
|
);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
|
|
|
@ -24,6 +24,11 @@ describe('#getters', () => {
|
||||||
expect(getters.getTwilioSMSInboxes(state).length).toEqual(1);
|
expect(getters.getTwilioSMSInboxes(state).length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('dialogFlowEnabledInboxes', () => {
|
||||||
|
const state = { records: inboxList };
|
||||||
|
expect(getters.dialogFlowEnabledInboxes(state).length).toEqual(5);
|
||||||
|
});
|
||||||
|
|
||||||
it('getInbox', () => {
|
it('getInbox', () => {
|
||||||
const state = {
|
const state = {
|
||||||
records: inboxList,
|
records: inboxList,
|
||||||
|
|
|
@ -3,16 +3,24 @@ class HookListener < BaseListener
|
||||||
message = extract_message_and_account(event)[0]
|
message = extract_message_and_account(event)[0]
|
||||||
return unless message.webhook_sendable?
|
return unless message.webhook_sendable?
|
||||||
|
|
||||||
message.account.hooks.each do |hook|
|
execute_hooks(event, message)
|
||||||
HookJob.perform_later(hook, event.name, message: message)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_updated(event)
|
def message_updated(event)
|
||||||
message = extract_message_and_account(event)[0]
|
message = extract_message_and_account(event)[0]
|
||||||
return unless message.webhook_sendable?
|
return unless message.webhook_sendable?
|
||||||
|
|
||||||
|
execute_hooks(event, message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def execute_hooks(event, message)
|
||||||
message.account.hooks.each do |hook|
|
message.account.hooks.each do |hook|
|
||||||
|
# In case of dialogflow, we would have a hook for each inbox.
|
||||||
|
# Which means we will execute the same hook multiple times if the below filter isn't there
|
||||||
|
next if hook.inbox.present? && hook.inbox != message.inbox
|
||||||
|
|
||||||
HookJob.perform_later(hook, event.name, message: message)
|
HookJob.perform_later(hook, event.name, message: message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :integrations_hook, class: 'Integrations::Hook' do
|
factory :integrations_hook, class: 'Integrations::Hook' do
|
||||||
app_id { 'slack' }
|
app_id { 'slack' }
|
||||||
inbox
|
|
||||||
account
|
account
|
||||||
settings { { test: 'test' } }
|
settings { { test: 'test' } }
|
||||||
status { Integrations::Hook.statuses['enabled'] }
|
status { Integrations::Hook.statuses['enabled'] }
|
||||||
|
|
|
@ -5,6 +5,7 @@ RSpec.describe HookJob, type: :job do
|
||||||
|
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
let(:hook) { create(:integrations_hook, account: account) }
|
let(:hook) { create(:integrations_hook, account: account) }
|
||||||
|
let(:inbox) { create(:inbox, account: account) }
|
||||||
let(:event_name) { 'message.created' }
|
let(:event_name) { 'message.created' }
|
||||||
let(:event_data) { { message: create(:message, account: account) } }
|
let(:event_data) { { message: create(:message, account: account) } }
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ RSpec.describe HookJob, type: :job do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls Integrations::Dialogflow::ProcessorService when its a dialogflow intergation' do
|
it 'calls Integrations::Dialogflow::ProcessorService when its a dialogflow intergation' do
|
||||||
hook = create(:integrations_hook, :dialogflow, account: account)
|
hook = create(:integrations_hook, :dialogflow, inbox: inbox, account: account)
|
||||||
allow(Integrations::Dialogflow::ProcessorService).to receive(:new).and_return(process_service)
|
allow(Integrations::Dialogflow::ProcessorService).to receive(:new).and_return(process_service)
|
||||||
expect(Integrations::Dialogflow::ProcessorService).to receive(:new)
|
expect(Integrations::Dialogflow::ProcessorService).to receive(:new)
|
||||||
described_class.perform_now(hook, event_name, event_data)
|
described_class.perform_now(hook, event_name, event_data)
|
||||||
|
|
|
@ -2,7 +2,8 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe Integrations::Dialogflow::ProcessorService do
|
describe Integrations::Dialogflow::ProcessorService do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
let(:hook) { create(:integrations_hook, :dialogflow, account: account) }
|
let(:inbox) { create(:inbox, account: account) }
|
||||||
|
let(:hook) { create(:integrations_hook, :dialogflow, inbox: inbox, account: account) }
|
||||||
let(:conversation) { create(:conversation, account: account, status: :pending) }
|
let(:conversation) { create(:conversation, account: account, status: :pending) }
|
||||||
let(:message) { create(:message, account: account, conversation: conversation) }
|
let(:message) { create(:message, account: account, conversation: conversation) }
|
||||||
let(:event_name) { 'message.created' }
|
let(:event_name) { 'message.created' }
|
||||||
|
|
|
@ -407,7 +407,8 @@ RSpec.describe Conversation, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#botintegration: when conversation created in inbox with dialogflow integration' do
|
describe '#botintegration: when conversation created in inbox with dialogflow integration' do
|
||||||
let(:hook) { create(:integrations_hook, :dialogflow) }
|
let(:inbox) { create(:inbox) }
|
||||||
|
let(:hook) { create(:integrations_hook, :dialogflow, inbox: inbox) }
|
||||||
let(:conversation) { create(:conversation, inbox: hook.inbox) }
|
let(:conversation) { create(:conversation, inbox: hook.inbox) }
|
||||||
|
|
||||||
it 'returns conversation status as pending' do
|
it 'returns conversation status as pending' do
|
||||||
|
|
Loading…
Reference in a new issue