- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们的网站上有一个网络聊天窗口,可以最小化/重新打开(这会保留相同的 token ,如果仍然有效)或关闭/重新打开(这确保我们检索新的 token )。当我们向机器人发送特定事件时,我们的机器人应该向我们打招呼,如下例所示:Welcome Event Example 。但是,当遵循特定模式时,网络聊天会卡在“WEB_CHAT/SET_REFERENCE_GRAMMAR_ID”操作上,并且我们的机器人不会向我们发送欢迎消息。
有人可以帮助我理解为什么网络聊天会在此操作上卡住吗?
下面的示例方法对于使用 JavaScript 重构 UI 是否可行?
重现步骤:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Web Chat</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style>
html,
body {
height: 100%;
}
body {
margin: 0;
}
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div style="width: 100%;">
<div style="width: 200px; float: left;">
<input type="button" onclick="openChat()" id="btnOpen" value="Open Chat" />
</div>
<div style="width: 200px; float: left;">
<input type="button" onclick="closeChat()" id="btnClose" value="Close Chat" />
</div>
<div style="width: 200px; float: left;">
<input type="button" onclick="minimizeChat()" id="btnMin" value="Minimize Chat" />
</div>
<div style="clear: both" id="webchat" role="main"></div>
</div>
<script>
const styleOptions = {
bubbleBackground: 'rgba(0, 0, 255, .1)',
bubbleFromUserBackground: 'rgba(0, 255, 0, .1)',
hideSendBox: false,
hideUploadButton: true, // default false
microphoneButtonColorOnDictate: '#F33',
sendBoxBackground: 'White',
sendBoxButtonColor: undefined, // defaults to subtle
sendBoxButtonColorOnDisabled: '#CCC',
sendBoxButtonColorOnFocus: '#333',
sendBoxButtonColorOnHover: '#999', // default '#333'
sendBoxDisabledTextColor: undefined, // defaults to subtle
sendBoxHeight: 40,
sendBoxMaxHeight: 200,
sendBoxTextColor: 'Black',
sendBoxBorderBottom: '',
sendBoxBorderLeft: '',
sendBoxBorderRight: '',
sendBoxBorderTop: 'solid 1px #E6E6E6',
sendBoxPlaceholderColor: undefined, // defaults to subtle
sendBoxTextWrap: true,
};
var secret = 'YOUR SECRET HERE';
var res = "";
var token = "";
const storeMiddleware = () => next => action => {
console.log(">>> HTML DISPATCH action: " + action.type);
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
sendEvent();
}
if (action.type === 'DIRECT_LINE/DISCONNECT_FULFILLED'){
setDirectLine(null);
setStore();
}
return next(action);
};
var newT = false;
var store = window.WebChat.createStore({}, storeMiddleware);
var wc = document.getElementById('webchat');
async function getRes() {
res = await fetch(
'https://directline.botframework.com/v3/directline/tokens/generate',
{
headers: {
Authorization: `Bearer ${secret}`,
'Content-type': 'application/json'
},
method: 'POST'
}
);
}
async function openChat() {
wc.style.display = "";
if (token == "") {
newT = true;
await getRes();
token = await res.json();
}
else {
newT = false;
}
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({ "token": token.token }), store,
styleOptions
},
wc);
document.querySelector('#webchat > *').focus();
}
function sendEvent() {
if (newT) {
store.dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: { name: 'webchat/join' }
});
}
}
function minimizeChat() {
wc.style.display = "none";
}
function closeChat() {
minimizeChat();
store.dispatch({type: 'DIRECT_LINE/DISCONNECT'});
token ="";
}
function setDirectLine(dl){
window.WebChat.directLine = dl;
}
function setStore(){
store = window.WebChat.createStore({}, storeMiddleware);
}
</script>
</body>
</html>
预期行为
您不会受到欢迎,并且在开发者控制台中,写入的最后一个操作是 ">>> HTML DISPATCH 操作:WEB_CHAT/SET_REFERENCE_GRAMMAR_ID"
其他上下文
如果将以下代码行从“closeChat”函数移至“minimizeChat”函数,机器人将正确地向我们打招呼。
store.dispatch({type: 'DIRECT_LINE/DISCONNECT'});
最佳答案
当我尝试时,你的代码可以工作。只有两点不同。
首先,我传入
res = wait fetch('http://localhost:3500/directline/token', { method: 'POST' });
代替您的await fetch()。我在出于开发目的而运行的“ token 服务器”中单独生成 token 。我使用 request 并发布选项,但选项基本相同,这让我......
二,我进去了
json: { 用户: { ID: 'dl_123' } }
需要经过哪条直达线路。该值是静态的,因为我不需要它是动态的以进行测试。如果我使用你的 fetch() 调用,它会失败。尝试一下。
关于javascript - 重构 BotFramework WebChat UI - javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60120341/
我在 C# 中为我的聊天机器人使用 botframework channel 直达线,最近我添加了 Bing 语音,用于文本到语音,反之亦然,但是当用户说话时,除了纯文本之外,是否还有音频文件作为消息
我有一个来自用户上传图片的字节数组。我需要使用 Bot-framework 在 Skype 和其他 channel 上将此字节数组呈现为图像 最佳答案 图像可以作为 base64 编码发送:
我正在使用自定义的 Microsoft Bot 框架 WebChat Client .当我的机器人无法为用户提供解决方案时,它能够与代理进行实时聊天服务。 我需要允许代理“先睹为快”当前正在输入 We
我正在运行 Windows 10 并想安装 BotFramework-Emulator。 链接 here说 Download packages for Mac, Windows, and Linux
我有一个机器人,它具有消息传递扩展功能。我遵循了一个例子 here .但是我没有使用卡片 View ,而是使用嵌入式 Web View 来显示我的自定义 UI(这是一个托管在 S3 中的 React
我需要维护聊天历史记录,并在页面刷新或关闭并打开窗口后将它们加载回窗口中。 问题:按钮/轮播/自适应卡/英雄卡事件/属性未加载(即,当我单击按钮或任何事件时,操作未发生)。描述:为了达到要求,我有两个
我正在尝试 Microsoft 的新 Botframework。使用 \n 发送消息时,消息中没有换行符。我该如何解决? 在 Telegram API 中有一个名为 parse_mode (https
我发布了一个使用机器人框架构建的机器人,但我不知道如何将它连接到企业内部网络上的 Skype for Business。 有谁知道是什么流程吗? ----- 埃德 最佳答案 尚不支持 Skype fo
我已经在 .Net Framework WebAPI 中使用 Microsoft.BotFramework 实现了一个聊天机器人,它正在运行,现在我想将它移植到 .Net Core 2,与其他项目共享
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 9 个月前关闭。 Improve this ques
我在英雄卡中使用粗体文本时遇到了一些问题,目前我是这样构建我的英雄卡的: var workloadCard = new HeroCard { Title = $
nodejs中bot框架的输入指示器 你好, 我正在使用 microsoft bot framework v4, node js,我需要在聊天机器人中实现输入。在发送原始响应之前,机器人应该响应 li
我正在创建一个在电报 chanel 上运行的机器人。当用户与机器人聊天时,它需要知道谁在聊天。所以他们必须在我的服务器上进行身份验证。 我想机器人会发送一个按钮,其中包含我的身份验证端点的链接(例如:
我正在打开(使用 OpenUrl)我控制的外部网页。在加载此网页期间,我希望从服务器直接关闭团队模式,或者通过调用团队客户端重新发送带有参数的消息,以便机器人可以以关闭响应进行响应(我正在工作)。 我
我正在尝试发送 Teams notification与 hero card或 Adaptive Card .我可以发送一条简单的短信作为 notification . 我不知道如何包装 Hero ca
我创建了一个简单的 android 应用程序,它使用 restfull jersey WS 通过 JSON 格式发送消息 我应该在连接机器人的应用程序中输入哪个 URL? 该机器人如何接收消息并发回响
我正在创建一个允许用户与现有 Web 服务交互的机器人。我希望用户能够与我的机器人开始对话并检索针对他们的个性化信息。 如何将机器人用户与其现有帐户相匹配?并非所有 channel 都使用电子邮件地址
我用我的机器人尝试了这种电子邮件模式,但是在Skype上发布时不起作用。它总是拒绝任何正常的有效电子邮件。 [Describe("email "), Prompt(QuestionWhatIsYour
我有一个名为“表单搜索”的对话框,它有一个自适应卡片。当我单击提交按钮时,控件不会转到下一个流程,而是以错误结束。但如果使用英雄卡,按钮点击会触发下一个流程。可能是什么问题。 session.mess
我开发了一个聊天机器人并将其部署在 Skype 上。我有一件新东西要添加到机器人中。 如果用户在 bot 中请求办公室出租车,则 bot 必须接受用户输入(如目的地、emp-name 等)并向特定邮件
我是一名优秀的程序员,十分优秀!