window.addEventListener('df-response-received',(event)=>{// Remove all non-text messages.event.detail.data.messages=event.detail.data.messages.filter(message=>{returnmessage.type==='text';});});
window.addEventListener('df-response-received',(event)=>{event.preventDefault();// Messenger won't handle the response.constmessenger=document.querySelector('df-messenger');event.detail.data.messages.forEach(message=>{if(message.type==='text'){messenger.renderCustomText(message.text);}});});
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eDialogflow CX Messenger offers various events that can be monitored using event listeners, allowing developers to interact with user interactions and agent responses.\u003c/p\u003e\n"],["\u003cp\u003eEvents like \u003ccode\u003edf-chat-open-changed\u003c/code\u003e, \u003ccode\u003edf-user-input-entered\u003c/code\u003e, \u003ccode\u003edf-request-sent\u003c/code\u003e, and \u003ccode\u003edf-response-received\u003c/code\u003e provide insights into the user's interaction with the chat and allow modification of the requests and responses.\u003c/p\u003e\n"],["\u003cp\u003eEvents such as \u003ccode\u003edf-messenger-error\u003c/code\u003e, \u003ccode\u003edf-session-expired\u003c/code\u003e, and \u003ccode\u003edf-session-ended\u003c/code\u003e provide status and error information, allowing for custom handling of sessions and agent errors.\u003c/p\u003e\n"],["\u003cp\u003eUser interaction events are available, such as \u003ccode\u003edf-button-clicked\u003c/code\u003e, \u003ccode\u003edf-chip-clicked\u003c/code\u003e, \u003ccode\u003edf-list-element-clicked\u003c/code\u003e, etc., that allow for the monitoring of the user's interaction with the agent and their messages.\u003c/p\u003e\n"],["\u003cp\u003eCertain events, like \u003ccode\u003edf-request-sent\u003c/code\u003e and \u003ccode\u003edf-response-received\u003c/code\u003e, allow for the modification or even prevention of default behaviors, such as request sending or response handling.\u003c/p\u003e\n"]]],[],null,["# Dialogflow CX Messenger JavaScript events\n\nDialogflow CX Messenger triggers a variety of events that you can create\n[event listeners](https://developer.mozilla.org/en-US/docs/Web/API/EventListener)\nfor.\nSome events have a `detail` object field,\nwhich provides more information about the event.\n\n`df-messenger-loaded`\n---------------------\n\nThe agent dialog is first loaded.\n\nDetail properties:\n\n- none\n\nFor example: \n\n window.addEventListener('df-messenger-loaded', () =\u003e {\n // Messenger is now ready.\n });\n\n`df-chat-open-changed`\n----------------------\n\nThe chat is opened or closed.\n| **Note:** Only active if the `df-messenger-chat-bubble` is used.\n\nDetail properties:\n\n- `isOpen` (`boolean`): new state of the chat\n\nFor example: \n\n window.addEventListener('df-chat-open-changed', (event) =\u003e {\n console.log(`Chat is ${event.detail.isOpen ? 'open' : 'closed'}`);\n });\n\n`df-user-input-entered`\n-----------------------\n\nThe user entered text.\n\nDetail properties:\n\n- `input` (`string`): value the user entered\n\nFor example: \n\n window.addEventListener('df-user-input-entered', (event) =\u003e {\n console.log(event.detail.input);\n });\n\n`df-request-sent`\n-----------------\n\nA request sent to the Dialogflow backend.\n| **Note:** The request can be manipulated. The changes are reflected in the request being sent. If the event's default is prevented, the request won't be sent.\n\nDetail properties:\n\n- `data` (`object`): data container\n- `data.requestBody` (`object`): request that was sent\n\nFor example: \n\n window.addEventListener('df-request-sent', (event) =\u003e {\n console.log('Request', event.detail.data.requestBody);\n });\n\n window.addEventListener('df-request-sent', (event) =\u003e {\n event.preventDefault(); // Messenger won't send the request.\n\n // Send request yourself.\n });\n\n`df-response-received`\n----------------------\n\nA response has arrived to the agent dialog.\n| **Note:** Messages can be manipulated, the changes will be reflected in the agent's response handling. If the event's default is prevented, the agent won't handle the response.\n\nDetail properties:\n\n- `data` (`object`): data container\n- `data.messages` (`object[]`): list of [parsed response messages](/dialogflow/cx/docs/concept/fulfillment)\n- `raw` (`object`): verbatim response that was received\n\nFor example: \n\n window.addEventListener('df-response-received', (event) =\u003e {\n // Remove all non-text messages.\n event.detail.data.messages = event.detail.data.messages.filter(message =\u003e {\n return message.type === 'text';\n });\n });\n\n window.addEventListener('df-response-received', (event) =\u003e {\n event.preventDefault(); // Messenger won't handle the response.\n\n const messenger = document.querySelector('df-messenger');\n event.detail.data.messages.forEach(message =\u003e {\n if (message.type === 'text') {\n messenger.renderCustomText(message.text);\n }\n });\n });\n\n`df-messenger-error`\n--------------------\n\nA request to the backend fails.\n\nDetail properties:\n\n- `error` (`object`): error that occurred\n\nFor example: \n\n window.addEventListener('df-messenger-error', (event) =\u003e {\n console.log(event.detail.error);\n });\n\n`df-session-expired`\n--------------------\n\nThe session with the agent expired.\n\nDetail properties:\n\n- none\n\nFor example: \n\n window.addEventListener('df-session-expired', () =\u003e {\n const messenger = document.querySelector('df-messenger');\n messenger.renderCustomText(`*Session expired*`, /* isBot= */ true);\n messenger.startNewSession({ retainHistory: true });\n });\n\n`df-session-ended`\n------------------\n\nThe session has ended.\n\nDetail properties:\n\n- none\n\nFor example: \n\n window.addEventListener('df-session-ended', () =\u003e {\n const messenger = document.querySelector('df-messenger');\n messenger.renderCustomText(`*Session ended*`, /* isBot= */ true);\n messenger.startNewSession({ retainHistory: true });\n });\n\n`df-url-suggested`\n------------------\n\nURLs of suggested resources.\n\nDetail properties:\n\n- `suggestedUrls` (`string[]`): list of suggested URLs\n\nFor example: \n\n window.addEventListener('df-url-suggested', (event) =\u003e {\n if (event.detail.suggestedUrls.length === 1) {\n window.location.href = event.detail.suggestedUrls[0];\n }\n });\n\n`df-accordion-clicked`\n----------------------\n\nUser clicked the accordion.\n\nDetail properties:\n\n- none\n\n`df-button-clicked`\n-------------------\n\nUser clicked a button.\n\nDetail properties:\n\n- `actionLink` (`string`): anchor href of the clicked button, if specified\n- `event` (`string`): [event](/dialogflow/cx/docs/concept/handler#event-custom) of the clicked button, if specified\n- `languageCode` (`string`): language code of the event if specified, otherwise the main language code\n- `text` (`string`): text of the clicked button\n\n window.addEventListener('df-button-clicked', (event) =\u003e {\n event.preventDefault(); // Messenger won't send the \"event\" request.\n\n // Handle \"event\" yourself.\n });\n\n`df-chip-clicked`\n-----------------\n\nUser clicked a chip.\n\nDetail properties:\n\n- `actionLink` (`string`): anchor href of the clicked chip, if specified\n- `text` (`string`): text of the clicked chip\n\n`df-citation-clicked`\n---------------------\n\nUser clicked a citation.\n\nDetail properties:\n\n- `actionLink` (`string`): anchor href of the citation\n- `title` (`string`): title of the citation\n\n`df-info-card-clicked`\n----------------------\n\nUser clicked an info-card.\n\nDetail properties:\n\n- `actionLink` (`string`): anchor href of the info-card\n- `title` (`string`): title of the info-card\n\n`df-list-element-clicked`\n-------------------------\n\nUser clicked a list element.\n\nDetail properties:\n\n- `actionLink` (`string`): anchor href of the list element, if specified\n- `event` (`string`): [event](/dialogflow/cx/docs/concept/handler#event-custom) of the clicked list element, if specified\n- `languageCode` (`string`): language code of the event if specified, otherwise the main language code\n- `title` (`string`): title of the list element\n\n window.addEventListener('df-list-element-clicked', (event) =\u003e {\n event.preventDefault(); // Messenger won't send the \"event\" request.\n\n // Handle \"event\" yourself.\n });\n\n`df-image-clicked`\n------------------\n\nUser clicked an image.\n\nDetail properties:\n\n- `actionLink` (`string`): anchor href of the image, if specified"]]