-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TCI-1133: add chat integration support (#827)
- Loading branch information
1 parent
071d521
commit 4961386
Showing
9 changed files
with
85 additions
and
14 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* This JS is partly taken from the script provided by the chatbot devs. | ||
* | ||
* As far as I can tell, I've taken all the useful code and added some | ||
* custom events so other scripts can react to the chatbot open or closed | ||
* state. The CSS and a2p.js initially provided are not functional. | ||
* | ||
* To support language switching in the future the chat bot should provide an | ||
* API we can send a language code to, to avoid cross origin issues. The method | ||
* of language switching in the CMS should trigger language change in the bot. | ||
*/ | ||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
// Custom events dispatch on open/close so elements outside of iframe | ||
// can react. | ||
const eventChatOpen = new CustomEvent("chat-open", { | ||
bubbles: true | ||
}); | ||
const eventChatClose = new CustomEvent("chat-close", { | ||
bubbles: true | ||
}); | ||
|
||
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; | ||
var eventer = window[eventMethod]; | ||
var messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message"; | ||
|
||
eventer(messageEvent, function(e) { | ||
if (e.data === "open" || e.message === "open") { | ||
// Allow event listener to react to open. | ||
window.dispatchEvent(eventChatOpen); | ||
} | ||
|
||
if (e.data === "close" || e.message === "close") { | ||
// Allow event listener to react to close. | ||
window.dispatchEvent(eventChatClose); | ||
} | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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