fix(captain): handle resolved conversation context (#14433)

# Pull Request Template

## Description

Fixes: https://github.com/chatwoot/chatwoot/issues/13880

Uses approaches discussed from:
https://github.com/chatwoot/chatwoot/pull/13883

Activity messages pertaining to resolve are included along with an
instruction for the LLM to choose whether to consider them or not along

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration.

locally and with specs


## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream
modules

---------

Co-authored-by: Sony Mathew <sony@chatwoot.com>
This commit is contained in:
Aakash Bakhle
2026-07-15 23:30:17 +05:30
committed by GitHub
co-authored by Sony Mathew
parent 9c68eed676
commit 354c2cab6b
10 changed files with 134 additions and 13 deletions
@@ -119,7 +119,13 @@ RSpec.describe 'Conversation Messages API', type: :request do
expect(Conversations::ActivityMessageJob)
.to(have_been_enqueued.at_least(:once)
.with(conversation, { account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity,
content: 'System reopened the conversation due to a new incoming message.' }))
content: 'System reopened the conversation due to a new incoming message.',
content_attributes: {
activity: {
type: 'conversation_status_changed',
status: 'open'
}
} }))
end
end
end
@@ -285,7 +285,8 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
account_id: conversation.account_id,
inbox_id: conversation.inbox_id,
message_type: :activity,
content: "Conversation was resolved by #{contact.name}"
content: "Conversation was resolved by #{contact.name}",
content_attributes: { activity: { type: 'conversation_status_changed', status: 'resolved' } }
}
)
end
@@ -202,7 +202,8 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
account_id: conversation.account_id,
inbox_id: conversation.inbox_id,
message_type: :activity,
content: "Conversation was resolved by #{contact.name}"
content: "Conversation was resolved by #{contact.name}",
content_attributes: { activity: { type: 'conversation_status_changed', status: 'resolved' } }
}
)
expect(response).to have_http_status(:success)