在我的机器人框架中,我使用一个输入表单作为一个自适应卡。现在,我希望检索用户在表单中提供的数据,并在用户单击submit按钮后在屏幕上显示。
有人能给我举个代码的例子吗,因为我似乎无法让它工作?
我正在使用下一个自适应卡:http://adaptivecards.io/samples/InputForm.html
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": 2,
"items": [
{
"type": "TextBlock",
"text": "Tell us about yourself",
"weight": "bolder",
"size": "medium"
},
{
"type": "TextBlock",
"text": "We just need a few more details to get you booked for the trip of a lifetime!",
"isSubtle": true,
"wrap": true
},
{
"type": "TextBlock",
"text": "Don't worry, we'll never share or sell your information.",
"isSubtle": true,
"wrap": true,
"size": "small"
},
{
"type": "TextBlock",
"text": "Your name",
"wrap": true
},
{
"type": "Input.Text",
"id": "myName",
"placeholder": "Last, First"
},
{
"type": "TextBlock",
"text": "Your email",
"wrap": true
},
{
"type": "Input.Text",
"id": "myEmail",
"placeholder": "youremail@example.com",
"style": "email"
},
{
"type": "TextBlock",
"text": "Phone Number"
},
{
"type": "Input.Text",
"id": "myTel",
"placeholder": "xxx.xxx.xxxx",
"style": "tel"
}
]
},
{
"type": "Column",
"width": 1,
"items": [
{
"type": "Image",
"url": "https://upload.wikimedia.org/wikipedia/commons/b/b2/Diver_Silhouette%2C_Great_Barrier_Reef.jpg",
"size": "auto"
}
]
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
]
}发布于 2017-11-10 07:34:59
关于在AdaptiveCards上使用node.js的示例有https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/cards-AdaptiveCards。你可以参考更多细节。
当使用Submit方法时,Bot将处理提交,您的bot将收到一条新消息,它的
value字段中填充了表单数据作为JSON对象。
在这个示例中,它创建一个函数processSubmitAction来处理提交消息。
var bot = new builder.UniversalBot(connector, function (session) {
if (session.message && session.message.value) {
// A Card's Submit Action obj was received
processSubmitAction(session, session.message.value);
return;
}
// ...
});要输出用户输入值,只需使用session.send()作为参考:
function processSubmitAction(session, value) {
session.send(JSON.stringify(value));
}https://stackoverflow.com/questions/47204965
复制相似问题