Webchat 不适用于 Internet Explorer
The Webchat doesnt work with Internet Explorer
我正在使用机器人,现在正尝试通过 Direct Line 实施机器人。
该机器人适用于 Google Chrome 和 Mozilla Firefox,但不适用于 Internet Explorer。
我得到的唯一错误是语法错误。您可以在本文下方的屏幕截图中看到这一点。
但是为什么呢?
<pre>
<div id="webchat" role="main"></div>
<script src="https://cdn.botframework.com/botframework-webchat/4.1.0/webchat-es5.js"></script>
<script>
const store = window.WebChat.createStore({}, ({ dispatch: dispatch }) => next => 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);
});
(async function () {
const token = '<Direct-Line-Secret>';
const region = 'westeurope';
const subscriptionKey = '<subscription-key>';
const webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({
subscriptionKey,
region
});
const styleOptions = {
botAvatarInitials: 'BC',
userAvatarInitials: 'UC'
};
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
store,
locale: 'de-DE',
styleOptions,
webSpeechPonyfillFactory
},
document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
<style>
#webchat {
margin: 0 auto;
clear: both;
padding: 0 0px;
position: fixed;
bottom: 0;
top: 0px;
padding-bottom: 0px;
width: 100%;
height: 100%;
}
</style>
</pre>
我可以看到您的脚本代码包含 => 箭头函数。
IE 浏览器不支持 arrow functions。
这就是它显示语法错误的原因。
您需要将 ES6 代码转换为 ES5 代码才能在 IE 浏览器中运行。
您可以尝试使用Babel.js转译代码。
它可以帮助您解决这个问题。
有用的线程link:
我正在使用机器人,现在正尝试通过 Direct Line 实施机器人。 该机器人适用于 Google Chrome 和 Mozilla Firefox,但不适用于 Internet Explorer。
我得到的唯一错误是语法错误。您可以在本文下方的屏幕截图中看到这一点。
但是为什么呢?
<pre>
<div id="webchat" role="main"></div>
<script src="https://cdn.botframework.com/botframework-webchat/4.1.0/webchat-es5.js"></script>
<script>
const store = window.WebChat.createStore({}, ({ dispatch: dispatch }) => next => 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);
});
(async function () {
const token = '<Direct-Line-Secret>';
const region = 'westeurope';
const subscriptionKey = '<subscription-key>';
const webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({
subscriptionKey,
region
});
const styleOptions = {
botAvatarInitials: 'BC',
userAvatarInitials: 'UC'
};
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
store,
locale: 'de-DE',
styleOptions,
webSpeechPonyfillFactory
},
document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
<style>
#webchat {
margin: 0 auto;
clear: both;
padding: 0 0px;
position: fixed;
bottom: 0;
top: 0px;
padding-bottom: 0px;
width: 100%;
height: 100%;
}
</style>
</pre>
我可以看到您的脚本代码包含 => 箭头函数。
IE 浏览器不支持 arrow functions。
这就是它显示语法错误的原因。
您需要将 ES6 代码转换为 ES5 代码才能在 IE 浏览器中运行。
您可以尝试使用Babel.js转译代码。
它可以帮助您解决这个问题。
有用的线程link: