botpress_workaround
by Erik
HTML
<!DOCTYPE html>
<html lang="en">
<header></header>
<body>
</body>
</html>
JavaScript
console.log('botpress');
var script = document.createElement('script');
script.src = 'https://cdn.botpress.cloud/webchat/v1/inject.js';
document.head.appendChild(script);
// script.onload = function() {
let server = 'https://tunnel.labsbit.com';
function store(payload) {
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload)
};
fetch(server+'/gen/store_payload', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
}
window.onload = function() {
if (window.botpressWebChat && typeof window.botpressWebChat.init === 'function') {
window.botpressWebChat.init({
"composerPlaceholder": "Chat with bot",
"botConversationDescription": "This chatbot was built surprisingly fast with Botpress",
"botId": "2f270d1d-8811-4471-9b87-5c5b35303c2d",
"hostUrl": "https://cdn.botpress.cloud/webchat/v1",
"messagingUrl": "https://messaging.botpress.cloud",
"clientId": "2f270d1d-8811-4471-9b87-5c5b35303c2d",
"webhookId": "4c52e0d1-9b4a-4098-a5a1-8927aa6040e6",
"lazySocket": true,
"themeName": "prism",
"frontendVersion": "v1",
"enableConversationDeletion": true,
"showPoweredBy": true,
"theme": "prism",
"themeColor": "#2563eb"
});
window.botpressWebChat.onEvent(function (event) {
//console.log(event);
if (event.type === 'TRIGGER') {
let convid = event['value']['convid'];
store({"convid": convid, "url": window.location.href})
console.log("convID", convid);
}
},['TRIGGER']
);
} else {
console.error("botpressWebChat.init is not available!");
}
};