src/website/iframeparent.html [156:201]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$(document).ready(function chatbotHandler() {
// When the chatbot ui iframe is ready to receive the
// dynamic config it sends the 'receivelexconfig' event to the parent
// For example, you can send dynamic config/parameters
// (e.g. username, geolocation) to the chatbot ui from here
$(document).one('receivelexconfig', function onReceiveLexConfig() {
var localTimeZone;
try {
localTimeZone = JSON.stringify(
Intl.DateTimeFormat().resolvedOptions().timeZone
);
} catch (err) {
localTimeZone = JSON.stringify(
new Date().getTimezoneOffset()
)
}
// sample config passing the local timezone in a sessionAttribute
var config = {
lex: {
sessionAttributes: {
localTimeZone: JSON.stringify(
Intl.DateTimeFormat().resolvedOptions().timeZone
)
}
}
};
// emit bot config event to send the dynamic config to the
// chatbot UI
// jquery can't trigger native events so use vanilla JS CustomEvent
var event = new CustomEvent('loadlexconfig', { detail: { config: config } });
document.dispatchEvent(event);
});
// Once the chatbot UI is ready, it sends a 'lexWebUiReady' event
$(document).on('lexWebUiReady', function onUpdateLexState(evt) {
// We are just sending a ping request here as an example
// This example uses an event instead of calling
// iframeLoader.api.ping() to show the asynchronous
// event API alternative
var event = new CustomEvent(
'lexWebUiMessage',
{ detail: {message: {event: 'ping'} } }
);
document.dispatchEvent(event);
});
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
src/website/parent.html [241:288]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$(document).ready(function chatbotHandler() {
// When the chatbot ui iframe is ready to receive the
// dynamic config it sends the 'receivelexconfig' event to the parent
// For example, you can send dynamic config/parameters
// (e.g. username, geolocation) to the chatbot ui from here
$(document).one('receivelexconfig', function onReceiveLexConfig() {
var localTimeZone;
try {
localTimeZone = JSON.stringify(
Intl.DateTimeFormat().resolvedOptions().timeZone
);
} catch (err) {
localTimeZone = JSON.stringify(
new Date().getTimezoneOffset()
)
}
// sample config passing the local timezone in a sessionAttribute
var config = {
lex: {
sessionAttributes: {
localTimeZone: JSON.stringify(
Intl.DateTimeFormat().resolvedOptions().timeZone
)
}
}
};
// emit bot config event to send the dynamic config to the
// chatbot UI
// jquery can't trigger native events so use vanilla JS CustomEvent
var event = new CustomEvent('loadlexconfig', { detail: { config: config } });
document.dispatchEvent(event);
});
// Once the chatbot UI is ready, it sends a 'lexWebUiReady' event
$(document).on('lexWebUiReady', function onUpdateLexState(evt) {
// We are just sending a ping request here as an example
// This example uses an event instead of calling
// iframeLoader.api.ping() to show the asynchronous
// event API alternative
var event = new CustomEvent(
'lexWebUiMessage',
{ detail: {message: {event: 'ping'} } }
);
document.dispatchEvent(event);
});
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -