Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70e20f8b35 |
@@ -68,7 +68,7 @@ class WebhookListener < BaseListener
|
|||||||
|
|
||||||
def inbox_created(event)
|
def inbox_created(event)
|
||||||
inbox, account = extract_inbox_and_account(event)
|
inbox, account = extract_inbox_and_account(event)
|
||||||
inbox_webhook_data = Inbox::EventDataPresenter.new(inbox).push_data
|
inbox_webhook_data = Inbox::EventDataPresenter.new(inbox).webhook_data
|
||||||
payload = inbox_webhook_data.merge(event: __method__.to_s)
|
payload = inbox_webhook_data.merge(event: __method__.to_s)
|
||||||
deliver_account_webhooks(payload, account)
|
deliver_account_webhooks(payload, account)
|
||||||
end
|
end
|
||||||
@@ -78,7 +78,7 @@ class WebhookListener < BaseListener
|
|||||||
changed_attributes = extract_changed_attributes(event)
|
changed_attributes = extract_changed_attributes(event)
|
||||||
return if changed_attributes.blank?
|
return if changed_attributes.blank?
|
||||||
|
|
||||||
inbox_webhook_data = Inbox::EventDataPresenter.new(inbox).push_data
|
inbox_webhook_data = Inbox::EventDataPresenter.new(inbox).webhook_data
|
||||||
payload = inbox_webhook_data.merge(event: __method__.to_s, changed_attributes: changed_attributes)
|
payload = inbox_webhook_data.merge(event: __method__.to_s, changed_attributes: changed_attributes)
|
||||||
deliver_account_webhooks(payload, account)
|
deliver_account_webhooks(payload, account)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ class Conversations::EventDataPresenter < SimpleDelegator
|
|||||||
|
|
||||||
# Like #push_data but with message text normalized for external integrations (webhooks).
|
# Like #push_data but with message text normalized for external integrations (webhooks).
|
||||||
def webhook_data
|
def webhook_data
|
||||||
push_data.merge(messages: webhook_push_messages)
|
push_data.merge(
|
||||||
|
account: account.webhook_data,
|
||||||
|
messages: webhook_push_messages
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -32,4 +32,8 @@ class Inbox::EventDataPresenter < SimpleDelegator
|
|||||||
channel: channel
|
channel: channel
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def webhook_data
|
||||||
|
push_data.merge(account: account.webhook_data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ describe AgentBotListener do
|
|||||||
create(:agent_bot_inbox, inbox: inbox, agent_bot: agent_bot)
|
create(:agent_bot_inbox, inbox: inbox, agent_bot: agent_bot)
|
||||||
expect(AgentBots::WebhookJob).to receive(:perform_later).with(
|
expect(AgentBots::WebhookJob).to receive(:perform_later).with(
|
||||||
agent_bot.outgoing_url,
|
agent_bot.outgoing_url,
|
||||||
hash_including(event: 'conversation_status_changed', changed_attributes: anything),
|
hash_including(event: 'conversation_status_changed', account: account.webhook_data, changed_attributes: anything),
|
||||||
:agent_bot_webhook,
|
:agent_bot_webhook,
|
||||||
hash_including(secret: agent_bot.secret)
|
hash_including(secret: agent_bot.secret)
|
||||||
).once
|
).once
|
||||||
|
|||||||
@@ -101,6 +101,15 @@ describe WebhookListener do
|
|||||||
).once
|
).once
|
||||||
listener.conversation_created(conversation_created_event)
|
listener.conversation_created(conversation_created_event)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'includes account details in the conversation payload' do
|
||||||
|
webhook = create(:webhook, inbox: inbox, account: account)
|
||||||
|
expect(WebhookJob).to receive(:perform_later).with(
|
||||||
|
webhook.url, hash_including(account: account.webhook_data), :account_webhook,
|
||||||
|
secret: webhook.secret, delivery_id: instance_of(String)
|
||||||
|
).once
|
||||||
|
listener.conversation_created(conversation_created_event)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when inbox is an API Channel' do
|
context 'when inbox is an API Channel' do
|
||||||
@@ -250,7 +259,7 @@ describe WebhookListener do
|
|||||||
|
|
||||||
context 'when webhook is configured' do
|
context 'when webhook is configured' do
|
||||||
it 'triggers webhook' do
|
it 'triggers webhook' do
|
||||||
inbox_data = Inbox::EventDataPresenter.new(inbox).push_data
|
inbox_data = Inbox::EventDataPresenter.new(inbox).webhook_data
|
||||||
webhook = create(:webhook, account: account, subscriptions: ['inbox_created'])
|
webhook = create(:webhook, account: account, subscriptions: ['inbox_created'])
|
||||||
expect(WebhookJob).to receive(:perform_later).with(
|
expect(WebhookJob).to receive(:perform_later).with(
|
||||||
webhook.url, inbox_data.merge(event: 'inbox_created'), :account_webhook,
|
webhook.url, inbox_data.merge(event: 'inbox_created'), :account_webhook,
|
||||||
@@ -258,6 +267,15 @@ describe WebhookListener do
|
|||||||
).once
|
).once
|
||||||
listener.inbox_created(inbox_created_event)
|
listener.inbox_created(inbox_created_event)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'includes account details in the inbox payload' do
|
||||||
|
webhook = create(:webhook, account: account, subscriptions: ['inbox_created'])
|
||||||
|
expect(WebhookJob).to receive(:perform_later).with(
|
||||||
|
webhook.url, hash_including(account: account.webhook_data), :account_webhook,
|
||||||
|
secret: webhook.secret, delivery_id: instance_of(String)
|
||||||
|
).once
|
||||||
|
listener.inbox_created(inbox_created_event)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -287,7 +305,7 @@ describe WebhookListener do
|
|||||||
it 'triggers webhook' do
|
it 'triggers webhook' do
|
||||||
webhook = create(:webhook, account: account, subscriptions: ['inbox_updated'])
|
webhook = create(:webhook, account: account, subscriptions: ['inbox_updated'])
|
||||||
|
|
||||||
inbox_data = Inbox::EventDataPresenter.new(inbox).push_data
|
inbox_data = Inbox::EventDataPresenter.new(inbox).webhook_data
|
||||||
changed_attributes_data = [{ 'name' => { 'previous_value': 'Inbox 1', 'current_value': inbox.name } }]
|
changed_attributes_data = [{ 'name' => { 'previous_value': 'Inbox 1', 'current_value': inbox.name } }]
|
||||||
|
|
||||||
expect(WebhookJob).to receive(:perform_later).with(
|
expect(WebhookJob).to receive(:perform_later).with(
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ RSpec.describe Conversations::EventDataPresenter do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#webhook_data' do
|
describe '#webhook_data' do
|
||||||
|
it 'includes account details for webhook consumers' do
|
||||||
|
expect(presenter.webhook_data[:account]).to eq(conversation.account.webhook_data)
|
||||||
|
end
|
||||||
|
|
||||||
it 'normalizes hard-break backslashes in message content' do
|
it 'normalizes hard-break backslashes in message content' do
|
||||||
message = create(:message, conversation: conversation, account: conversation.account,
|
message = create(:message, conversation: conversation, account: conversation.account,
|
||||||
message_type: :outgoing, content: "Hello\\\nWorld")
|
message_type: :outgoing, content: "Hello\\\nWorld")
|
||||||
|
|||||||
Reference in New Issue
Block a user