var msgId = null, body = null;
function onPostMessage(event) {
if (!event || !event.data || !event.data.msgId) return; //required. check for msgId
msgId = event.data.msgId;
body = JSON.parse(event.data.body);//optional body to be passed from AI builder.
//this body can be used anywhere in the code later
console.error('Error on parsing body data', error);
window.addEventListener('message', onPostMessage);
parent.postMessage({ type: "webview.frame.ready" }, '*');//trigger this whenever webview is ready to be displayed
//call this function with text(to be shown in chat) along with optional data
function closeFrame(text, data) {
//data passed here will be available as a res param in the Res function of webview.
parent.postMessage({ type: "webview", jsonData: JSON.stringify(data || {}), msgId: msgId, text: text }, '*');