Skip to content

Commit 66ad56a

Browse files
Implement chat button event listener and auto-launch
Added event listener for chat button creation and auto-launch functionality during business hours.
1 parent 07ea38c commit 66ad56a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

godwin/sdb3/messaging.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ <h2>godwin@sdb3.org</h2>
7171
isWithinBusinessHours = true;
7272
console.log('onEmbeddedMessagingWithinBusinessHours: ' + isWithinBusinessHours);
7373
});
74+
window.addEventListener('onEmbeddedMessagingButtonCreated', function() {
75+
console.log('onEmbeddedMessagingButtonCreated: fired, isWithinBusinessHours = ' + isWithinBusinessHours);
76+
try {
77+
var launchChat = () => {
78+
console.log('pointerdown: isWithinBusinessHours = ' + isWithinBusinessHours);
79+
if (isWithinBusinessHours) {
80+
window ? .embeddedservice_bootstrap ? .utilAPI ? .launchChat();
81+
}
82+
};
83+
document.getElementById("embeddedMessagingConversationButton").addEventListener("pointerdown", launchChat, true);
84+
if (!window ? .embeddedservice_bootstrap ? .prechatAPI || isLaunched)
85+
return;
86+
if (isWithinBusinessHours) {
87+
console.log('onEmbeddedMessagingButtonCreated: auto-launching chat');
88+
window ? .embeddedservice_bootstrap ? .utilAPI ? .launchChat();
89+
isLaunched = true;
90+
}
91+
} catch (err) {
92+
console.error('Error launching chat: ', err);
93+
}
94+
});
7495
</script>
7596
<script type='text/javascript'>
7697
function initEmbeddedMessaging() {

0 commit comments

Comments
 (0)