I changed my code from webchat 3 to webchat 4 and also changed style options and so some other stuff. Everything works fine....just the web-chat rendering creates a problem. Here is my code:
(async function() {
const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
headers: {
Authorization: `Bearer [MYBEARER]`,
},
method: 'POST'
});
const { token } = await res.json();
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
//console.log(action);
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: { language: window.navigator.language }
}
});
}
return next(action);
});
const styleOptions = {
botAvatarInitials: 'EY',
userAvatarInitials: 'YOU'
};
const {
createCognitiveServicesSpeechServicesPonyfillFactory,
createDirectLine,
renderWebChat
} = window.WebChat;
var div = document.createElement("div");
document.getElementsByTagName('body')[0].appendChild(div);
div.outerHTML = "<div id='botDiv' style='width: 400px; height: 0px; margin:10px; position: fixed; bottom: 0; right:0; z-index: 1000; background-color:#252525; border:1px solid #252525;'><div id='botTitleBar' style='height: 40px; width: 400px; position:fixed; cursor: pointer; background-color:#FFE600;'></div></div>";
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
webSpeechPonyfillFactory: window.WebChat.createBrowserWebSpeechPonyfillFactory(),
store,
userID: `You`,
username: 'Web Chat User',
locale: 'en-US',
language: 'en-US',
styleOptions
}, document.getElementById('botDiv'));
document.querySelector('#botDiv > *').focus();
document.querySelector('body').addEventListener('click', function (e) {
e.target.matches = e.target.matches || e.target.msMatchesSelector;
if (e.target.matches('#chatbotheader')) {
var botDiv = document.querySelector('#botDiv');
botDiv.style.height = "0px";
document.getElementById("mychat").style.display = "block";
};
});
document.getElementById("mychat").addEventListener("click", function (e) {
document.getElementById("botDiv").style.height = '500px';
e.target.style.display = "none";
})
}()).catch(err => console.error(err));;
I also have in my header all js and css links:
<link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
<link rel="stylesheet" href="~/css/botchatey.css">
<script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
<script crossorigin="anonymous" src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
HERE IS THE PROBLEM: The whole layout runs perfectly when I remove the "window.WebChat.renderWebChat" function. I can max- and minimize the chatwindow which I cerate in the div-outerHTML.
When I add the renderWebChat function it seems that the excapsulated DIV with the id "botTitleBar" gets eaten and is not showing up. If I press F12 at the running solution I cannot see this DIV in the code running. I spent hours on this now. Any help is highly welcome! Please!