【发布时间】:2020-07-30 14:10:54
【问题描述】:
我在 Azure 中部署了一个 Bot,该 Bot 显示欢迎消息 OnMemberAdd。它的自适应卡因此输入的值被发送到 stepcontext.value。我已经将它与多个渠道集成,对于直达线,我想绕过欢迎卡并将消息直接传递给 stepcontext.value 以便显示第二个提示而不是第一个提示。我已经尝试了以下方法,但它不起作用,请帮助。
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Web Chat: Send welcome event</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 id="webchat"></div>
<script>
(async function() {
// In this demo, we are using Direct Line token from MockBot.
// Your client code must provide either a secret or a token to talk to your bot.
// Tokens are more secure. To learn about the differences between secrets and tokens
// and to understand the risks associated with using secrets, visit https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication?view=azure-bot-service-4.0
const { token } = { token};
// We are using a customized store to add hooks to connect event
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'userInfo',
value: { fname:'user', lname:'test', pnumber:'0678775453'}
}
});
}
return next(action);
});
const styleOptions = {
botAvatarImage:
'',
botAvatarInitials: 'Chatbot',
userAvatarImage: '',
userAvatarInitials: 'User',
showNub: true,
bubbleFromUserNubOffset: 'bottom',
bubbleFromUserNubSize: 10,
bubbleFromUserBorderColor: '#0077CC',
bubbleNubOffset: 'top',
bubbleNubSize: 0,
bubbleBorderColor: '#009900',
sendBoxButtonColor: '#009900',
hideUploadButton: true,
hideSendBox : true
};
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({ token }),
store,
styleOptions
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
</body>
</html>
我尝试通过邮递员发送数据,效果很好,但是当我使用上面的代码发送数据时,它不起作用。
邮递员身体
{
"type": "message",
"from": {
"id": "user1"
},
"value":
{
"fname":"user",
"lname":"test",
"pnumber":"0678787543"
}
}
【问题讨论】:
-
您能否详细说明“它不起作用”是什么意思?您目前已将其设置为在 WebChat 连接到机器人后立即发送该消息,我认为这不是您想要的。或者你是说消息根本没有通过?
-
我正在使用来自 MS Web Chat 示例的 HTML/Java 脚本模板。我可以将消息作为文本发送,即 stepcontext.context.activity.text,但在我的情况下,机器人期待 stepcontext.context.activity.value 中的数据。所以我试图以价值发送数据,但消息没有到达机器人。我使用邮递员尝试了相同的步骤并且它有效。我正在寻找一个答案来了解如何将数据发送到 stepcontext.context.activity.value。如果需要更多信息,请告诉我..
-
补充以上内容,我想在网络聊天连接后立即发送值。我尝试调试但未确定为什么当我在有效负载中发送值时消息没有到达 Chatbot,我没有看到任何错误。
标签: javascript node.js botframework chatbot adaptive-cards