Agent bot conversations now feel more natural because AgentBot tokens can toggle typing status, so end users see a live typing indicator in the widget while the bot is preparing a reply. This keeps the interaction responsive and human-like without weakening token authorization boundaries. ## Closes - https://github.com/chatwoot/chatwoot/issues/8928 - https://linear.app/chatwoot/issue/CW-5205 ## How to test 1. Open the widget and start a conversation as a customer. 2. Connect an AgentBot to the same inbox. 3. Trigger `toggle_typing_status` with the AgentBot token (`typing_status: on`). 4. Confirm the customer sees the typing indicator in the widget. 5. Trigger `toggle_typing_status` with `typing_status: off` and confirm the indicator disappears. ## What changed - Added `toggle_typing_status` to bot-accessible conversation endpoints. - Restricted bot-accessible endpoint usage to `AgentBot` token owners only (non-user tokens like `PlatformApp` remain unauthorized). - Updated typing status flow to preserve AgentBot identity in dispatch/broadcast paths. - Added request coverage for AgentBot success and PlatformApp unauthorized behavior. - Added Swagger documentation for `POST /api/v1/accounts/{account_id}/conversations/{conversation_id}/toggle_typing_status` and regenerated swagger artifacts.
26 lines
725 B
Ruby
26 lines
725 B
Ruby
class Conversations::TypingStatusManager
|
|
include Events::Types
|
|
|
|
attr_reader :conversation, :user, :params
|
|
|
|
def initialize(conversation, user, params)
|
|
@conversation = conversation
|
|
@user = user
|
|
@params = params
|
|
end
|
|
|
|
def trigger_typing_event(event, is_private)
|
|
Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: @conversation, user: @user, is_private: is_private)
|
|
end
|
|
|
|
def toggle_typing_status
|
|
case params[:typing_status]
|
|
when 'on'
|
|
trigger_typing_event(CONVERSATION_TYPING_ON, params[:is_private])
|
|
when 'off'
|
|
trigger_typing_event(CONVERSATION_TYPING_OFF, params[:is_private])
|
|
end
|
|
# Return the head :ok response from the controller
|
|
end
|
|
end
|