chatwoot/app/javascript/widget/api
Muhsin Keloth b3d0af84c4
fix(widget): Queue SDK-set conversation attributes and labels for first message (#13912)
### Description

When integrating the web widget via the JS SDK, customers call
setConversationCustomAttributes and setLabel on chatwoot:ready — before
any conversation exists. These API calls silently fail because the
backend endpoints require an existing conversation. When the visitor
sends their first message, the conversation is created without those
attributes/labels, so the message_created webhook payload is missing the
expected metadata.

This change queues SDK-set conversation custom attributes and labels in
the widget store when no conversation exists yet, and includes them in
the API request when the first message (or attachment) creates the
conversation. The backend now permits and applies these params during
conversation creation — before the message is saved and webhooks fire.

###  How to test

  1. Configure a web widget without a pre-chat form.
2. Open the widget on a test page and run the following in the browser
console after chatwoot:ready:
`window.$chatwoot.setConversationCustomAttributes({ plan: 'enterprise'
});`
`window.$chatwoot.setLabel('vip');` // must be a label that exists in
the account
  3. Send the first message from the widget.
4. Verify in the Chatwoot dashboard that the conversation has plan:
enterprise in custom attributes and the vip label applied.
5. Set up a webhook subscriber for `message_created` confirm the first
payload includes the conversation metadata.
6. Verify that calling `setConversationCustomAttributes` / `setLabel` on
an existing conversation still works as before (direct API path, no
regression).
  7. Verify the pre-chat form flow still works as expected.
2026-04-02 12:09:24 +04:00
..
specs fix(widget): Queue SDK-set conversation attributes and labels for first message (#13912) 2026-04-02 12:09:24 +04:00
agent.js chore: Refactor widget (#5621) 2022-10-14 09:13:11 +05:30
article.js feat: Add store and API to support articles in widget (#7616) 2023-07-26 14:08:27 -07:00
campaign.js chore: Refactor widget (#5621) 2022-10-14 09:13:11 +05:30
contacts.js chore: Enhance contact merge action for identified users (#4886) 2022-06-23 15:48:56 +05:30
conversation.js fix(widget): Queue SDK-set conversation attributes and labels for first message (#13912) 2026-04-02 12:09:24 +04:00
conversationLabels.js Feature: Website SDK (#653) 2020-04-03 13:04:58 +05:30
endPoints.js fix(widget): Queue SDK-set conversation attributes and labels for first message (#13912) 2026-04-02 12:09:24 +04:00
events.js fix: Add missing referer & initiated_at.timestamp to events (#2920) 2021-08-31 11:46:15 +05:30
integration.js feat: Add the support for video calls with Dyte in the live-chat widget (#6208) 2023-01-09 11:52:31 -08:00
message.js Feature: Rich Message Types (#610) 2020-04-10 16:42:37 +05:30