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>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
0126d8c668
commit
579bce3ee4
@@ -17,10 +17,10 @@ class AgentBotListener < BaseListener
|
||||
|
||||
def conversation_updated(event)
|
||||
conversation = extract_conversation_and_account(event)[0]
|
||||
return if conversation.assignee_agent_bot.blank?
|
||||
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s)
|
||||
process_webhook_bot_event(conversation.assignee_agent_bot, payload)
|
||||
inbox = conversation.inbox
|
||||
event_name = __method__.to_s
|
||||
payload = conversation.webhook_data.merge(event: event_name)
|
||||
agent_bots_for(inbox, conversation).each { |agent_bot| process_webhook_bot_event(agent_bot, payload) }
|
||||
end
|
||||
|
||||
def message_created(event)
|
||||
|
||||
@@ -61,6 +61,22 @@ describe AgentBotListener do
|
||||
let(:event_name) { 'conversation.updated' }
|
||||
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation) }
|
||||
|
||||
context 'when agent bot is not configured' do
|
||||
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
|
||||
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')).once
|
||||
listener.conversation_updated(event)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when conversation is assigned to an agent bot' do
|
||||
before do
|
||||
conversation.update!(assignee_agent_bot: agent_bot, assignee: nil)
|
||||
@@ -72,13 +88,6 @@ describe AgentBotListener do
|
||||
listener.conversation_updated(event)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when conversation is not assigned to an agent bot' do
|
||||
it 'does not send webhook' do
|
||||
expect(AgentBots::WebhookJob).not_to receive(:perform_later)
|
||||
listener.conversation_updated(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#webwidget_triggered' do
|
||||
|
||||
Reference in New Issue
Block a user