Javascript MS BOT框架(自适应卡):如何从directline发送值(Stepcontext.value)
我在Azure中部署了一个机器人,该机器人在MemberAdd上显示欢迎消息。它的自适应卡,以便将输入的值发送到stepcontext.value。我已将其与多个通道集成,对于directline,我希望绕过欢迎卡,将消息直接传递给stepcontext.value,以便显示第二个提示,而不是第一个提示。我已经尝试了下面的方法,但不起作用,请帮助Javascript MS BOT框架(自适应卡):如何从directline发送值(Stepcontext.value),javascript,node.js,botframework,chatbot,adaptive-cards,Javascript,Node.js,Botframework,Chatbot,Adaptive Cards,我在Azure中部署了一个机器人,该机器人在MemberAdd上显示欢迎消息。它的自适应卡,以便将输入的值发送到stepcontext.value。我已将其与多个通道集成,对于directline,我希望绕过欢迎卡,将消息直接传递给stepcontext.value,以便显示第二个提示,而不是第一个提示。我已经尝试了下面的方法,但不起作用,请帮助 <!DOCTYPE html> <html lang="en-US"> <head> <titl
<!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>
你太近了!您有两个选择:
WEB\u聊天/发送\u事件
,并包括名称
属性:const store=window.WebChat.createStore({},({dispatch})=>next=>action=>{
如果(action.type==='DIRECT\u LINE/CONNECT\u completed'){
派遣({
键入:“网络聊天/发送事件”,
有效载荷:{
名称:“用户信息”,
值:{fname:'user',lname:'test',pnnumber:'0678775453'}
}
});
}
返回下一步(操作);
});
WEB\u聊天/发送消息
,包括文本
属性,并更改为频道数据
:const store=window.WebChat.createStore({},({dispatch})=>next=>action=>{
如果(action.type==='DIRECT\u LINE/CONNECT\u completed'){
派遣({
键入:“网络聊天/发送消息”,
有效载荷:{
文本:“用户信息”,
channelData:{fname:'user',lname:'test',pnumber:'0678775453'}
}
});
}
返回下一步(操作);
});
===
更新
我可以看到它通过使用您的代码很好。在onTurn
/OnTurnAsync
中放置一个断点,您将看到当用户连接时,您得到:
你能详细解释一下“它不起作用”是什么意思吗?你现在已经设置好在WebChat连接到机器人后立即发送该消息,我不相信这是你想要的。或者你是说消息根本没有通过?我使用的是MS Web聊天示例中的HTML/Java脚本模板。我能够以文本形式发送消息,即stepcontext.context.activity.text,但在我的情况下,bot需要stepcontext.context.activity.value中的数据。因此,我试图以值形式发送数据,但消息没有到达bot。我用邮递员试过同样的方法,效果很好。我想知道如何将数据发送到stepcontext.context.activity.value。如果需要更多信息,请告诉我。要添加到上述内容,我希望在连接webchat后尽快发送值。我已经尝试过调试,但没有确定当我在有效负载中发送值时消息没有到达聊天机器人的原因,我没有看到任何错误。我已经尝试了上述两个选项,我无法让它工作。它没有显示任何错误,但数据没有到达机器人。我不确定我是否遗漏了什么。1)
var-reply=stepContext.Context.Activity.Value
2)var-reply=stepContext.Context.Activity.ChannelData
@KrishnaS你能用你完整的html
(减去秘密)更新你的问题吗?@KrishnaS我已经更新了我的答案,以表明你的代码按照预期/期望的方式运行。
{
"type": "message",
"from": {
"id": "user1"
},
"value":
{
"fname":"user",
"lname":"test",
"pnumber":"0678787543"
}
}