Question

How can I retrieve the URL of a Web Widget conversation for use in AI Agents - Advanced?

Answer

You can retrieve the URL of a web widget conversation by using messaging metadata to populate the URL in a custom ticket field.

The workflow includes the steps below.

  • 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 custom text ticket field

  1. Create a checkbox ticket field and name it URL. Under the Permissions section, select Customers can edit.
  2. (Optional) Add the created text field to all the ticket forms your agents use for messaging conversations with customers.
  3. Access your ticket fields to copy the URL ticket field ID.

Step 2: Create the AI agent action

  1. Select your Messaging AI Agent and click into Settings > CRM Integration to ensure that Sunshine Conversations is authorized. If it is not, you can click Add CRM integration and select Messaging to get started.
  2. Create an action with the following:
    • Name | Get URL
    • Targets | Sunshine Conversations
    • Task | Get Conversation
    • Field to retrieve | Metadata
    • Key | Paste the the value zen:ticket_field:<fieldId> and replace the <fieldId> with the ticket ID from step 1.
  3. Set the action to run in your workflow. If you would like it to run at the beginning of every conversation, you can go to Settings > AI Agent Settings > Events and Actions and click in the top right to Add action then select Conversation started and finally select the action from the previous step.

Step 3: Add the Web Widget JavaScript

  1. Add the following code to the website or help center that the Web Widget is embedded. 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 are adding this JavaScript to a help center, include it in the script.js template. For more information, see the article: Customizing the CSS or JavaScript

  2. The URL will now be recorded in the messaging metadata as part your AI Agents - Advanced workflows.
Note: 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.

For more information, see this article: Using messaging metadata with the Zendesk Web Widget and SDKs

Powered by Zendesk