Node.js 检查是否在自适应卡中填写了输入表单
您可以在自适应卡中使用输入表单。 但是,如何在不进入下一个对话框的情况下检查字段是否已填充。因此,在我单击submit按钮后,它应该检查字段是否已填写 代码:nodejsNode.js 检查是否在自适应卡中填写了输入表单,node.js,botframework,adaptive-cards,Node.js,Botframework,Adaptive Cards,您可以在自适应卡中使用输入表单。 但是,如何在不进入下一个对话框的情况下检查字段是否已填充。因此,在我单击submit按钮后,它应该检查字段是否已填写 代码:nodejs 示例:自适应卡没有客户端验证,因此您必须从bot服务中检索值并在服务器上进行验证。如果字段没有按预期归档,那么您可以向用户发送一个响应,其中包含他们应该填写的内容。看一看这个机器人,看一个例子,在对话框中完成几个步骤,当提示输入时,发送一个空白响应,机器人将以友好的消息响应,要求您填写字段 源代码:您可以在bot应用程序中验证
示例:自适应卡没有客户端验证,因此您必须从bot服务中检索值并在服务器上进行验证。如果字段没有按预期归档,那么您可以向用户发送一个响应,其中包含他们应该填写的内容。看一看这个机器人,看一个例子,在对话框中完成几个步骤,当提示输入时,发送一个空白响应,机器人将以友好的消息响应,要求您填写字段
源代码:您可以在bot应用程序中验证输入并控制“注水”对话框。 例如
希望ut有帮助。但是如果用户填写错误,您如何防止机器人再次发送卡片?
var bot = new builder.UniversalBot(connector, [(session,args,next) => {
if (session.message && session.message.value) {
// A Card's Submit Action obj was received
if (processSubmitAction(session, session.message.value)) {
next(session.message.value)
}
return;
}
// Display Welcome card with Hotels and Flights search options
var card = {
'contentType': 'application/vnd.microsoft.card.adaptive',
'content': {
"$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",
"value": "somevalue",
"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"
}]
}
};
var msg = new builder.Message(session)
.addAttachment(card);
session.send(msg);
}, (session, results) => {
session.send(JSON.stringify(results))
}]);
function processSubmitAction(session, value) {
var defaultErrorMessage = 'Please complete all the search parameters';
if (!value.myName) {
session.send(defaultErrorMessage);
return false;
} else {
return true;
}
}