feat(captain): show document conversation usage (#15140)
## Summary Adds conversation usage to Captain documents and user created FAQs. Only knowledge used in a Captain answer sent to the contact is counted. Lookups that end in a handoff are excluded. Administrators can see how many distinct conversations used a knowledge record. Document usage appears in the Usage tab inside document details. User created FAQ usage appears on each FAQ card and opens in a conversation panel. Deleted conversations are excluded from counts, sorting, and conversation lists. Usage shown in side panel <img width="2342" height="1502" alt="CleanShot 2026-08-12 at 18 29 02@2x" src="https://github.com/user-attachments/assets/67301051-6df5-4eb6-9b8d-e1fc75bb02f2" /> Sorting options <img width="580" height="241" alt="image" src="https://github.com/user-attachments/assets/078566b7-481b-491b-b484-c2fef481f1b1" /> ## Access Conversation usage is available only to administrators. Agents can still view documents and FAQs, but they cannot see usage counts, the Usage tab, the "Most used" sort, or conversation usage details. The API applies the same rule. An agent request for `sort=most_used` is rejected. ## Performance and pagination Document and FAQ lists return 25 records per page. Usage counts are calculated only for the records in each page. Conversation usage panels load 25 conversations at a time and show a "Load more" action when more conversations are available. The generated FAQs tab also keeps its existing 25 item pagination. The count queries use the JSON indexes on `document_ids` and `used_faq_ids`. The "Most used" sort aggregates one assistant's sessions once before it sorts and returns the requested document page. ## How to test 1. Sign in as an administrator and open the Captain documents page for an assistant with tracked document usage. 2. Open a document and confirm that the Usage tab shows the distinct conversation count and the matching conversations. 3. Select "Most used" and confirm that documents are ordered by distinct conversation usage. 4. Open the user created FAQs page and confirm that FAQ cards show their usage count and open the matching conversations. 5. Confirm that usage panels show 25 conversations first and can load the next page. 6. Trigger a knowledge lookup that ends in a handoff and confirm that it does not increase document or FAQ usage. 7. Sign in as an agent and confirm that usage counts, usage details, and the "Most used" sort are not available. ## Closes [CW-7498](https://linear.app/chatwoot/issue/CW-7498/fe)
This commit is contained in:
@@ -78,7 +78,9 @@ Rails.application.routes.draw do
|
||||
resources :scenarios
|
||||
end
|
||||
resources :agent_sessions, only: [:show]
|
||||
resources :assistant_responses
|
||||
resources :assistant_responses do
|
||||
get :drilldown, on: :member
|
||||
end
|
||||
resources :faq_suggestions, only: [:index, :show, :update] do
|
||||
post :approve, on: :member
|
||||
post :dismiss, on: :member
|
||||
@@ -93,6 +95,7 @@ Rails.application.routes.draw do
|
||||
end
|
||||
resources :documents, only: [:index, :show, :create, :destroy] do
|
||||
post :sync, on: :member
|
||||
get :drilldown, on: :member
|
||||
end
|
||||
resource :tasks, only: [], controller: 'tasks' do
|
||||
post :rewrite
|
||||
|
||||
Reference in New Issue
Block a user