classCustomFeedbackElementextendsHTMLElement{constructor(){super();// It is not strictly required but recommended to contain the custom// element in a shadow root.this.renderRoot=this.attachShadow({mode:'open'});}// Web component Lifecycle method.connectedCallback(){constwrapper=document.createElement('div');// Build the component as required.constbutton=document.createElement('button');button.innerText='Submit';button.addEventListener('click',()=>{this._onSubmitClick();});wrapper.appendChild(button);this.renderRoot.appendChild(wrapper);}// Called when Submit button is clicked._onSubmitClick(){constevent=newCustomEvent("df-custom-submit-feedback-clicked",{// `detail` may be any string,// this will be sent to the backend to be stored.detail:JSON.stringify({"usefulness":2,"accuracy":3,}),// Required to propagate up the DOM tree// https://developer.mozilla.org/en-US/docs/Web/API/Event/bubblesbubbles:true,// Required to propagate across ShadowDOM// https://developer.mozilla.org/en-US/docs/Web/API/Event/composedcomposed:true,});this.dispatchEvent(event);}}(function(){// Registers the element. This name must be "df-external-custom-feedback".customElements.define('df-external-custom-feedback',CustomFeedbackElement);})();
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[[["\u003cp\u003eThis integration enables you to embed a customizable chat dialog for your Dialogflow CX agent directly into your website.\u003c/p\u003e\n"],["\u003cp\u003eYou can configure the integration for either authenticated or unauthenticated end-user access to the agent's query features.\u003c/p\u003e\n"],["\u003cp\u003eThe setup process involves selecting the desired authentication type (unauthenticated or authorized API) in the Dialogflow CX console and obtaining embeddable HTML code.\u003c/p\u003e\n"],["\u003cp\u003eOnce set up, you can paste the provided HTML code into your webpage's body element to display the chat dialog and include a viewport meta tag for responsive layout.\u003c/p\u003e\n"],["\u003cp\u003eThe chat dialog's appearance and behavior can be further customized through HTML, CSS, JavaScript events and functions, in addition to the option to implement a custom feedback element.\u003c/p\u003e\n"]]],[],null,["# Dialogflow CX Messenger\n\nThis integration provides a customizable chat dialog for your [agent](/dialogflow/cx/docs/concept/agent)\nthat can be embedded in your website.\n\nSetup\n-----\n\nThis integration can allow either authenticated or unauthenticated\nend-user agent query access.\n\n### Unauthenticated setup\n\n\n| **Note:** Make sure [billing is enabled](/dialogflow/cx/docs/quick/setup#billing) on your project before testing the integration.\n\nTo set up unauthenticated access to your Dialogflow CX Messenger agent:\n\n1. Go to the [Dialogflow CX console](https://dialogflow.cloud.google.com/cx/projects).\n2. Choose your Google Cloud project.\n3. Select your agent.\n4. Select the **Manage** tab.\n5. Click **Integrations** in the left sidebar menu.\n6. Click **Connect** on **Dialogflow CX Messenger**.\n7. A configuration dialog opens.\n8. If the integration was previously setup for this agent, you will see embeddable HTML code. Regardless of whether you want what authenticated or unauthenticated, click the **Disable...** button at the bottom of the dialog, so you can reconfigure the settings in the next step.\n9. Select an **Environment**.\n10. Select **Unauthenticated API**.\n11. Select a style.\n12. Optionally restrict domain access.\n13. Click **Enable the unauthenticated API**.\n14. The dialog will show the embeddable HTML code that can be embedded on your website. Copy this code.\n15. Click **Done**.\n\n\u003cbr /\u003e\n\n### Authenticated setup\n\n\nTo set up authenticated access to your Dialogflow CX Messenger agent:\n\n1. Go to the [Dialogflow CX console](https://dialogflow.cloud.google.com/cx/projects).\n2. Choose your Google Cloud project.\n3. Select your agent.\n4. Select the **Manage** tab.\n5. Click **Integrations** in the left sidebar menu.\n6. Click **Connect** on **Dialogflow CX Messenger**.\n7. A configuration dialog opens.\n8. If the integration was previously setup for this agent, you will see embeddable HTML code. Regardless of whether you want what authenticated or unauthenticated, click the **Disable...** button at the bottom of the dialog, so you can reconfigure the settings in the next step.\n9. Select an **Environment**.\n10. Select **Authorized API**.\n11. Select a style.\n12. Optionally restrict domain access.\n13. Click **Enable the authorized API**.\n14. The dialog will show the embeddable HTML code that can be embedded on your website. Copy this code.\n15. Click **Done**.\n16. Set up the OAuth client:\n 1. [Create an OAuth consent screen](https://developers.google.com/workspace/guides/configure-oauth-consent) for your organization. Add `https://www.googleapis.com/auth/cloud-platform` as a required scope.\n 2. [Create an OAuth 2.0 Client ID](https://developers.google.com/workspace/guides/create-credentials#oauth-client-id). Under **Authorized JavaScript origins** , specify the HTTP origins that are allowed to host and query your agent. For example, `https://your-company.com`.\n 3. [Provide end-users with permission to query your agent](/dialogflow/cx/docs/concept/access-control). Add each of your end-users or a [group](/iam/docs/groups-in-cloud-console) as a principal with the [**Dialogflow API Client**](/dialogflow/cx/docs/concept/access-control#iam-roles) and [**Service Usage Consumer**](/service-usage/docs/access-control#predefined_roles) roles.\n\n| **Note:** The first time an end-user uses the authenticated integration, they are asked to select which scopes to allow. They must allow the Cloud API.\n\n\u003cbr /\u003e\n\nEmbed\n-----\n\n\nPaste the embed code you copied above in a webpage on your website.\nThe `\u003cscript\u003e` and `\u003cdf-messenger\u003e` HTML elements\nshould be in the `\u003cbody\u003e` element of your page.\n\nIf you are using an authenticated integration,\nset the `oauth-client-id` attribute for `\u003cdf-messenger\u003e`\nto your Oauth client id. And if you want to use end-users' identities for [tool\nauthentication](/dialogflow/cx/docs/concept/playbook/tool#openapi_tool_api_authentication),\nset the `access-token-name` attribute with any name you like.\nThen use Bearer Token with value `$session.params.`\u003cvar class=\"edit\" label=\"the access token name you set\" translate=\"no\"\u003eACCESS_TOKEN_NAME\u003c/var\u003e\nfor tool authentication.\n\nUpdate any other attributes that require updating.\n\nTo allow for responsive layouts,\nalso add the following to your `\u003chead\u003e` element: \n\n \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n\n\u003cbr /\u003e\n\nCustomization\n-------------\n\nThere are many\n[HTML customizations](/dialogflow/cx/docs/concept/integration/dialogflow-messenger/html)\nand\n[CSS customizations](/dialogflow/cx/docs/concept/integration/dialogflow-messenger/css)\nthat you can apply to affect the appearance and behavior of the chat dialog.\n\nJavaScript\n----------\n\nThere are many\n[Javascript events](/dialogflow/cx/docs/concept/integration/dialogflow-messenger/javascript-events)\nand\n[Javascript functions](/dialogflow/cx/docs/concept/integration/dialogflow-messenger/javascript-functions)\nthat you can use to interact with the chat dialog.\n\nExample\n-------\n\nThe following example shows\nHTML customization,\nCSS customization,\nand JavaScript event handling: \n\n \u003c!DOCTYPE html\u003e\n \u003chtml\u003e\n \u003chead\u003e\n \u003cmeta charset=\"utf-8\"\u003e\n \u003cmeta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" /\u003e\n \u003cmeta http-equiv=\"Pragma\" content=\"no-cache\" /\u003e\n \u003cmeta http-equiv=\"Expires\" content=\"0\" /\u003e\n \u003ctitle\u003eMy chat\u003c/title\u003e\n \u003cstyle\u003e\n df-messenger {\n /*\n * Customize as required. df-messenger will fill the\n * space that is provided.\n */\n position: absolute;\n right: 0;\n top: 0;\n bottom: 0;\n width: 320px;\n }\n \u003c/style\u003e\n \u003cscript src=\"https://www.gstatic.com/dialogflow-console/fast/df-messenger/prod/v1/df-messenger.js\"\u003e\u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdf-messenger\n location=\"global\" \u003c!-- TODO: update agent location as needed --\u003e\n project-id=\"my-project-id\" \u003c!-- TODO: update project ID --\u003e\n agent-id=\"my-agent-id\" \u003c!-- TODO: update agent ID --\u003e\n language-code=\"en\" \u003c!-- TODO: update agent language as needed --\u003e\n \u003e\n \u003cdf-messenger-chat\n chat-title=\"Agent Name\" \u003c!-- TODO: update dialog title as needed --\u003e\n \u003e\u003c/df-messenger-chat\u003e\n \u003c/df-messenger\u003e\n\n \u003cscript\u003e\n // An example of handling events: Navigate to the first suggested URL.\n document.addEventListener('df-url-suggested', (event) =\u003e {\n if (Array.isArray(event.detail.suggestedUrls) &&\n event.detail.suggestedUrls.length) {\n window.location.href = event.detail.suggestedUrls[0];\n }\n });\n \u003c/script\u003e\n \u003c/body\u003e\n \u003c/html\u003e\n\nFulfillment\n-----------\n\nThere are many\n[fulfillment response types](/dialogflow/cx/docs/concept/integration/dialogflow-messenger/fulfillment)\nthat you can use for agent responses.\n\nAnswer Feedback\n---------------\n\nIf [answer feedback](/dialogflow/cx/docs/concept/answer-feedback#enable_feedback) is enabled, by default the chat dialog will add thumbs up thumb_up\nand thumbs down thumb_down\nbuttons to the user interface.\nDuring the conversation,\nan end-user can click these buttons to provide feedback on the agent responses.\nIf the user selects thumbs down,\nthey can optionally provide a reason for the negative feedback.\n\n### Custom Feedback component\n\nTo specify a custom feedback element, a new [custom element](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements) has to be defined on the website.\nTo submit the feedback, the element must emit a `df-custom-submit-feedback-clicked` event. The contained `detail` field must be a string. \n\n class CustomFeedbackElement extends HTMLElement {\n constructor() {\n super();\n // It is not strictly required but recommended to contain the custom\n // element in a shadow root.\n this.renderRoot = this.attachShadow({mode: 'open'});\n }\n\n // Web component Lifecycle method.\n connectedCallback() {\n const wrapper = document.createElement('div');\n\n // Build the component as required.\n const button = document.createElement('button');\n button.innerText = 'Submit';\n button.addEventListener('click', () =\u003e {\n this._onSubmitClick();\n });\n wrapper.appendChild(button);\n\n this.renderRoot.appendChild(wrapper);\n }\n\n // Called when Submit button is clicked.\n _onSubmitClick() {\n const event = new CustomEvent(\"df-custom-submit-feedback-clicked\", {\n // `detail` may be any string,\n // this will be sent to the backend to be stored.\n detail: JSON.stringify({\n \"usefulness\": 2,\n \"accuracy\": 3,\n }),\n // Required to propagate up the DOM tree\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/bubbles\n bubbles: true,\n // Required to propagate across ShadowDOM\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/composed\n composed: true,\n });\n this.dispatchEvent(event);\n }\n }\n\n (function() {\n // Registers the element. This name must be \"df-external-custom-feedback\".\n customElements.define('df-external-custom-feedback', CustomFeedbackElement);\n })();\n\nDebugging\n---------\n\nTo test your agent with Dialogflow CX Messenger locally:\n\n- Embed the Dialogflow CX Messenger element in a page as described above.\n- Start a local HTTP server for that page with a specific port.\n- Access that page at `http://localhost:port_number`."]]