[英]MS BOT Framework (adaptive cards): How to send value (Stepcontext.Value) from directline
I have deployed a Bot in Azure, the Bot displays a welcome message OnMemberAdd.我在 Azure 中部署了一个 Bot,Bot 显示欢迎消息 OnMemberAdd。 Its adaptive card so the entered value are sent to stepcontext.value.
它的自适应卡因此输入的值被发送到 stepcontext.value。 I have integrated it with multiple channels, for directline, I would like to bypass the welcome card and pass the message directly to stepcontext.value so the second prompt is displayed instead of first.
我已经将它与多个渠道集成,对于直达线,我想绕过欢迎卡并将消息直接传递给 stepcontext.value 以便显示第二个提示而不是第一个提示。 I have tried the below but it does not work, please help.
我已经尝试了以下方法,但它不起作用,请帮助。
<!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>
I have tried to send the data via postman and it works well but when I do it using above code it does not work.我试图通过 postman 发送数据,它运行良好,但是当我使用上面的代码执行它时它不起作用。
Postman body Postman体
{
"type": "message",
"from": {
"id": "user1"
},
"value":
{
"fname":"user",
"lname":"test",
"pnumber":"0678787543"
}
}
You're so close: You have two options:你是如此接近:你有两个选择:
WEB_CHAT/SEND_EVENT
and include the name
property:WEB_CHAT/SEND_EVENT
并包含name
属性: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);
});
WEB_CHAT/SEND_MESSAGE
, include the text
property, and change to channelData
:WEB_CHAT/SEND_MESSAGE
,包括text
属性,并更改为channelData
:const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_MESSAGE',
payload: {
text: 'userInfo',
channelData: { fname:'user', lname:'test', pnumber:'0678775453'}
}
});
}
return next(action);
});
=== ===
I can see it coming through just fine using your code.我可以看到它使用您的代码很好。 Put a breakpoint in
onTurn
/ OnTurnAsync
and you'll see that when a user connects you get:在
onTurn
/ OnTurnAsync
中放置一个断点,您会看到当用户连接时,您会得到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.