-
-
Save kellylara/0f972cf7370e40fce91f6996429c7f0b to your computer and use it in GitHub Desktop.
Custom handoff from Ada to Gorgias sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width" /> | |
| <title>Ada-Gorgias Sample</title> | |
| <style> | |
| .show-button { | |
| display: block !important; | |
| } | |
| #chat-button { | |
| display: none; | |
| } | |
| #ada-button-frame { | |
| display: none; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Custom handoff from Ada to Gorgias sample</h1> | |
| <p>Remember to update your Ada bot handle and add your live chat platform's embed script before testing.</p> | |
| <!-- Hello! This sample demonstrates how you can initiate a handoff from Ada to Gorgias Live Chat. The following sample scripts should be placed just before the closing body tag or loaded after the main live chat elements are available. --> | |
| <script> | |
| (function () { | |
| let gorgiasButton, adaButton; | |
| function setLastChatOpened(name) { | |
| sessionStorage.setItem("lastChatOpened", name); | |
| } | |
| function switchChatWidgets() { | |
| GorgiasChat.on("widget:closed", function (data) { | |
| gorgiasButton.classList.remove("show-button"); | |
| adaButton.classList.add("show-button"); | |
| setLastChatOpened("ada"); | |
| }); | |
| gorgiasButton.classList.add("show-button"); | |
| adaButton.classList.remove("show-button"); | |
| } | |
| function checkLastChatOpened() { | |
| const lastChatOpened = sessionStorage.getItem("lastChatOpened"); | |
| if (lastChatOpened === "gorgias") { | |
| switchChatWidgets(); | |
| } else { | |
| adaButton.classList.add("show-button"); | |
| } | |
| } | |
| function formatMessage(msg) { | |
| const msgArray = msg.split(/(?=SUMMARY: |USER: |BOT: )/); | |
| // If the chat transcript setting is reversed in the builder Dashboard (i.e. sorted from newest to oldest), the slice() params may need to be updated. | |
| if (msg.length >= 4000) { | |
| return `LAST FEW CHAT INTERACTIONS:\n\n${msgArray.slice(-6).join("")}`; | |
| } | |
| return msg; | |
| } | |
| window.adaSettings = { | |
| adaReadyCallback: () => { | |
| adaButton = document.querySelector("#ada-button-frame"); | |
| GorgiasChat.init().then(function () { | |
| gorgiasButton = document.querySelector("#chat-button"); | |
| checkLastChatOpened(); | |
| }); | |
| }, | |
| eventCallbacks: { | |
| custom_handoff: (event) => { | |
| if (window.GorgiasChat && GorgiasChat.hasOwnProperty("captureUserEmail")) { | |
| // The following 2 lines are optional. They are needed to set the email we save from Ada in Gorgias Chat | |
| const userEmail = event.user_data.global.email; | |
| GorgiasChat.captureUserEmail(userEmail); | |
| switchChatWidgets(); | |
| GorgiasChat.open(); | |
| setLastChatOpened("gorgias"); | |
| const chatTranscript = event.chatter_transcript; | |
| const message = formatMessage(chatTranscript); | |
| GorgiasChat.sendMessage(message); | |
| adaEmbed.toggle(); | |
| } | |
| }, | |
| }, | |
| }; | |
| })(); | |
| </script> | |
| <script | |
| id="__ada" | |
| data-handle="ada-example" | |
| src="https://static.ada.support/embed2.js" | |
| ></script> | |
| <!-- Replace this line with your Gorgias Chat Widget Javascript snippet --> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment