detect/listen for action.submit 如何从自适应卡
How detect/listen for action.submit from adaptive card
我正在使用 botframework(企业机器人模板)和 LUIS.ai:
我的问题是,当我填写自定义自适应卡片(它有三个文本输入字段)并单击提交时,我收到以下消息:"I’m sorry, I’m not able to help with that."我可以在模拟器中看到提交按钮发布返回输入的值,但我不确定如何监听按钮 action.My 我的想法是我必须监听何时调用操作的 ID,但我不完全确定该怎么做那。
下面是调用对话框的代码:
public static IMessageActivity SendTicketFormCard(ITurnContext turnContext, dynamic data)
{
var response = turnContext.Activity.CreateReply();
var introcard = File.ReadAllText(@".\dialogs\main\resources\Ticket_Fields.json");
response.Attachments = new List<Attachment>();
response.Attachments.Add(new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(introcard),
});
return response;
}
JSON 对话框如下所示:
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"horizontalAlignment": "Center",
"size": "Medium",
"weight": "Bolder",
"color": "Dark",
"text": "Search Ticket"
},
{
"type": "TextBlock",
"id": "94358428-5ef2-43a5-9056-d3cac1abfabd",
"text": "Ticket ID:",
"maxLines": 1
},
{
"type": "Input.Text",
"id": "68e1e180-4cdc-4ad6-bb8f-743554f1f58b",
"placeholder": "Ticket ID (required)",
"maxLength": 10
},
{
"type": "TextBlock",
"id": "2da1df9d-7f61-4e5c-9ff9-7aba2c5b306b",
"text": "Summary:",
"maxLines": 1
},
{
"type": "Input.Text",
"id": "403979a3-ccba-4baa-a885-2abca754cc69",
"placeholder": "Summary (optional)",
"maxLength": 250,
"isMultiline": true
},
{
"type": "TextBlock",
"id": "a25464c7-07ea-4270-995f-5e57b783b52d",
"text": "Status:",
"maxLines": 1
},
{
"type": "Input.Text",
"id": "7794d725-feb5-4516-9786-d18684892106",
"placeholder": "Status (optional)",
"maxLength": 30
}
],
"actions": [
{
"type": "Action.Submit",
"id": "783fe2e4-4056-449e-8cc6-5dc9c406222a",
"title": "Search"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
消息 "I’m sorry, I’m not able to help with that." 是对企业模板 MainDialog class. You can find the message in MainStrings.resx 中 "None" LUIS 意图的响应。
自适应卡的提交操作向机器人发送了一条没有文本的消息,然后 LUIS 尝试使用消息的文本来解释该消息的意图,但没有文本。提交的数据将包含在 activity 的 Value
属性 中。要从 Value
属性 中读取数据,您需要使用卡片的输入字段 ID 作为键。
private const string TICKETFIELD = "68e1e180-4cdc-4ad6-bb8f-743554f1f58b";
private const string SUMMARYFIELD = "403979a3-ccba-4baa-a885-2abca754cc69";
private const string STATUSFIELD = "7794d725-feb5-4516-9786-d18684892106";
您需要检查收到的消息以查看它们是否没有文本,然后将其作为可能的提交操作进行响应。您可以在 LUIS 确定意图为 "None," 后执行此操作,但您也可以在消息发送到 LUIS 之前进行检查。转到您的 MainDialog 的 RouteAsync 方法并将所有现有代码包装在 else
块中,然后您可以将响应提交操作的代码放入您的 if
块中:
protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
if (string.IsNullOrEmpty(activity.Text))
{
dynamic value = dc.Context.Activity.Value;
await turnContext.SendActivityAsync($"Ticket = {value[TICKETFIELD]}, Summary = {value[SUMMARYFIELD]}, Status = {value[STATUSFIELD]}");
}
else
{
// All the code that was already there
}
}
当您点击自适应卡片中的提交按钮时,频道会在频道数据对象中发回一个 "postback": "true" 令牌。与此同时,在提交按钮上配置的数据将在 json 中的值对象中发送。您需要解析此值以获取采取进一步操作所需的详细信息。我已经发布了一个关于这个的post。请查看
BotFramework Reactive Adaptive Cards: How to Read Data on Action Buttons in Adaptive Cards
我正在使用 botframework(企业机器人模板)和 LUIS.ai:
我的问题是,当我填写自定义自适应卡片(它有三个文本输入字段)并单击提交时,我收到以下消息:"I’m sorry, I’m not able to help with that."我可以在模拟器中看到提交按钮发布返回输入的值,但我不确定如何监听按钮 action.My 我的想法是我必须监听何时调用操作的 ID,但我不完全确定该怎么做那。
下面是调用对话框的代码:
public static IMessageActivity SendTicketFormCard(ITurnContext turnContext, dynamic data)
{
var response = turnContext.Activity.CreateReply();
var introcard = File.ReadAllText(@".\dialogs\main\resources\Ticket_Fields.json");
response.Attachments = new List<Attachment>();
response.Attachments.Add(new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(introcard),
});
return response;
}
JSON 对话框如下所示:
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"horizontalAlignment": "Center",
"size": "Medium",
"weight": "Bolder",
"color": "Dark",
"text": "Search Ticket"
},
{
"type": "TextBlock",
"id": "94358428-5ef2-43a5-9056-d3cac1abfabd",
"text": "Ticket ID:",
"maxLines": 1
},
{
"type": "Input.Text",
"id": "68e1e180-4cdc-4ad6-bb8f-743554f1f58b",
"placeholder": "Ticket ID (required)",
"maxLength": 10
},
{
"type": "TextBlock",
"id": "2da1df9d-7f61-4e5c-9ff9-7aba2c5b306b",
"text": "Summary:",
"maxLines": 1
},
{
"type": "Input.Text",
"id": "403979a3-ccba-4baa-a885-2abca754cc69",
"placeholder": "Summary (optional)",
"maxLength": 250,
"isMultiline": true
},
{
"type": "TextBlock",
"id": "a25464c7-07ea-4270-995f-5e57b783b52d",
"text": "Status:",
"maxLines": 1
},
{
"type": "Input.Text",
"id": "7794d725-feb5-4516-9786-d18684892106",
"placeholder": "Status (optional)",
"maxLength": 30
}
],
"actions": [
{
"type": "Action.Submit",
"id": "783fe2e4-4056-449e-8cc6-5dc9c406222a",
"title": "Search"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
消息 "I’m sorry, I’m not able to help with that." 是对企业模板 MainDialog class. You can find the message in MainStrings.resx 中 "None" LUIS 意图的响应。
自适应卡的提交操作向机器人发送了一条没有文本的消息,然后 LUIS 尝试使用消息的文本来解释该消息的意图,但没有文本。提交的数据将包含在 activity 的 Value
属性 中。要从 Value
属性 中读取数据,您需要使用卡片的输入字段 ID 作为键。
private const string TICKETFIELD = "68e1e180-4cdc-4ad6-bb8f-743554f1f58b";
private const string SUMMARYFIELD = "403979a3-ccba-4baa-a885-2abca754cc69";
private const string STATUSFIELD = "7794d725-feb5-4516-9786-d18684892106";
您需要检查收到的消息以查看它们是否没有文本,然后将其作为可能的提交操作进行响应。您可以在 LUIS 确定意图为 "None," 后执行此操作,但您也可以在消息发送到 LUIS 之前进行检查。转到您的 MainDialog 的 RouteAsync 方法并将所有现有代码包装在 else
块中,然后您可以将响应提交操作的代码放入您的 if
块中:
protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
if (string.IsNullOrEmpty(activity.Text))
{
dynamic value = dc.Context.Activity.Value;
await turnContext.SendActivityAsync($"Ticket = {value[TICKETFIELD]}, Summary = {value[SUMMARYFIELD]}, Status = {value[STATUSFIELD]}");
}
else
{
// All the code that was already there
}
}
当您点击自适应卡片中的提交按钮时,频道会在频道数据对象中发回一个 "postback": "true" 令牌。与此同时,在提交按钮上配置的数据将在 json 中的值对象中发送。您需要解析此值以获取采取进一步操作所需的详细信息。我已经发布了一个关于这个的post。请查看 BotFramework Reactive Adaptive Cards: How to Read Data on Action Buttons in Adaptive Cards