Question
How can I retrieve the URL of a Web Widget conversation for use in AI Agents - Advanced?
Answer
Use messaging metadata to store the URL in a custom ticket field.
The workflow includes these steps:
- Step 1: Create the custom text ticket field
- Step 2: Create the AI agent action
- Step 3: Add the Web Widget JavaScript
Step 1: Create the text ticket field
- In Admin Center, click Objects and rules in the sidebar, then select Tickets > Fields
- Click Add field, and then select Text
- Under Display name, add URL
- In Permissions, select Customers can edit
- Create a custom text ticket field and name it URL. Under the Permissions section, select Customers can edit.
- Click Save
- Optionally, add the created text field to all ticket forms your agents use for messaging with customers
-
Access your ticket fields to copy the URL ticket field ID
Step 2: Create the AI agent action
- Select your messaging AI Agent. Open Settings > CRM Integration to verify that Sunshine Conversations is authorized. If not, click Add CRM integration and select Messaging.
-
Create an action with these settings:
- Name | Get URL
- Targets | Sunshine Conversations
- Task | Get Conversation
- Field to retrieve | Metadata
-
Key | Paste the value
zen:ticket_field:<fieldId>and replace the<fieldId>with the ticket field ID from step 1
- Set the action to run in your workflow. To run it at the start of every conversation, go to Settings > AI Agent Settings > Events and Actions. Click Add action, select Conversation started, then select the action from the previous step.
Step 3: Add the Web Widget JavaScript
-
Add this code to the website or help center where you embed the Web Widget. Replace the
<fieldId>value with the field ID from step 1:<script> zE('messenger:set', 'conversationFields', [{ id: '<fieldId>', value: window.location.href }]); </script>If you add this JavaScript to a help center, include it in the script.js template. For more information, see the article: Customizing the CSS or JavaScript
- The system now records the URL in the messaging metadata as part of your AI Agents - Advanced workflows
Disclaimer: This article is provided for instructional purposes only. Zendesk does not support or guarantee the code. Zendesk also can't provide support for third-party technologies such as JavaScript, jQuery, or CSS. Post any issues you have in the comments section or try searching for a solution online.