Compare commits

...
Author SHA1 Message Date
MuhsinandClaude Opus 4.6 b6a3c551bc fix(agent-bot): include changed_attributes in conversation_updated webhook
Include changed_attributes in the conversation_updated payload so bots
can identify what changed — e.g. check for assignee_agent_bot_id to
distinguish bot assignment from other conversation updates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 09:34:29 +04:00
MuhsinandClaude Opus 4.6 579bce3ee4 fix(agent-bot): use consistent pattern for conversation_updated handler
Match the same pattern as conversation_opened/conversation_resolved,
using agent_bots_for to send to both inbox-level and conversation-level
bots. Update specs accordingly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 13:44:40 +04:00
Muhsin KelothandGitHub 0126d8c668 Merge branch 'develop' into fix/agent-bot-assignment-webhook 2026-04-02 13:11:58 +04:00
Muhsin KelothandGitHub 4ba3d18be0 Merge branch 'develop' into fix/agent-bot-assignment-webhook 2026-04-02 11:55:25 +04:00
MuhsinandClaude Opus 4.6 27a7e4fa0b fix(agent-bot): use conversation_updated instead of assignee_changed
CONVERSATION_UPDATED already fires when assignee_agent_bot_id changes,
so no modification to AssignmentHandler is needed. Just listen for
conversation_updated in AgentBotListener instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 11:23:37 +04:00
MuhsinandClaude Opus 4.6 287a75b524 fix(agent-bot): address rubocop offenses in assignee_changed handler
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 10:53:09 +04:00
MuhsinandClaude Opus 4.6 40d00d895d fix(agent-bot): dispatch webhook event on agent bot assignment
When an AgentBot is assigned to a conversation after the first message,
the bot receives no event and cannot respond. This adds ASSIGNEE_CHANGED
event dispatch for agent bot assignment changes and handles it in the
AgentBotListener to notify the bot via webhook.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 10:52:33 +04:00
2 changed files with 55 additions and 0 deletions
+9
View File
@@ -15,6 +15,15 @@ class AgentBotListener < BaseListener
agent_bots_for(inbox, conversation).each { |agent_bot| process_webhook_bot_event(agent_bot, payload) }
end
def conversation_updated(event)
conversation = extract_conversation_and_account(event)[0]
changed_attributes = extract_changed_attributes(event)
inbox = conversation.inbox
event_name = __method__.to_s
payload = conversation.webhook_data.merge(event: event_name, changed_attributes: changed_attributes)
agent_bots_for(inbox, conversation).each { |agent_bot| process_webhook_bot_event(agent_bot, payload) }
end
def message_created(event)
message = extract_message_and_account(event)[0]
inbox = message.inbox
+46
View File
@@ -57,6 +57,52 @@ describe AgentBotListener do
end
end
describe '#conversation_updated' do
let(:event_name) { 'conversation.updated' }
context 'when agent bot is not configured' do
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation) }
it 'does not send webhook' do
expect(AgentBots::WebhookJob).not_to receive(:perform_later)
listener.conversation_updated(event)
end
end
context 'when agent bot is configured on inbox' do
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation) }
it 'sends webhook to the inbox agent bot' do
create(:agent_bot_inbox, inbox: inbox, agent_bot: agent_bot)
expect(AgentBots::WebhookJob).to receive(:perform_later).with(agent_bot.outgoing_url,
conversation.webhook_data.merge(event: 'conversation_updated',
changed_attributes: nil)).once
listener.conversation_updated(event)
end
end
context 'when conversation is assigned to an agent bot' do
let!(:event) do
Events::Base.new(event_name, Time.zone.now, conversation: conversation,
changed_attributes: { 'assignee_agent_bot_id' => [nil, agent_bot.id] })
end
before do
conversation.update!(assignee_agent_bot: agent_bot, assignee: nil)
end
it 'sends webhook with changed_attributes to the assigned agent bot' do
expected_changed_attributes = [{ 'assignee_agent_bot_id' => { previous_value: nil, current_value: agent_bot.id } }]
expect(AgentBots::WebhookJob).to receive(:perform_later).with(agent_bot.outgoing_url,
conversation.webhook_data.merge(
event: 'conversation_updated',
changed_attributes: expected_changed_attributes
)).once
listener.conversation_updated(event)
end
end
end
describe '#webwidget_triggered' do
let(:event_name) { 'webwidget.triggered' }