我正在尝试从聊天机器人中的自适应卡中检索数据,但我不知道如何检索。
我已经使用创建了一个自适应卡,并让它在聊天机器人中成功地显示,但是一旦选择了'Submit‘,我希望能够检索用户输入的数据。
我相信这与我没有一个端点可供消息发送的事实有关,但我不知道如何声明一个端点。
任何帮助都是非常感谢的!
C#
private async Task choiceCAIAResult(IDialogContext context, IAwaitable<string> result)
{
string message = await result;
if (message == "Yes")
{
var replyMessage = context.MakeMessage();
CreateAdaptiveCardApplicationJson(context, result);
// replyMessage.Attachments = new List<Attachment> { attachment };
// await context.PostAsync(replyMessage);
}
if (message == "No")
{
var replyMessage = context.MakeMessage();
Attachment attachment = GetCAIAHeroCard();
replyMessage.Attachments = new List<Attachment> { attachment };
await context.PostAsync(replyMessage);
}
}
private async Task CreateAdaptiveCardApplicationJson(IDialogContext context, IAwaitable<string> result)
{
var returnMessage = context.MakeMessage();
var json = await GetCardText("adaptiveCard");
var results = AdaptiveCard.FromJson(json);
var card = results.Card;
returnMessage.Attachments.Add(new Attachment()
{
Content = card,
ContentType = AdaptiveCard.ContentType,
Name = "Card",
});
card.Actions.Add(new AdaptiveSubmitAction() {
Title = "Next",
});
Debug.WriteLine(returnMessage.Attachments[0].Content);
await context.PostAsync(returnMessage);
}
public async Task<string> GetCardText(string cardName)
{
var path = HostingEnvironment.MapPath($"/Dialogs/{cardName}.json");
if (!File.Exists(path))
return string.Empty;
using (var f = File.OpenText(path))
{
return await f.ReadToEndAsync();
}
}JSON
{ "type": "AdaptiveCard", "body": [
{
"type": "TextBlock",
"horizontalAlignment": "Center",
"size": "Large",
"text": "Residential Aged Care Online Application Form",
"wrap": true
},
{
"type": "TextBlock",
"size": "Medium",
"text": "Applicant Details"
},
{
"type": "Input.Text",
"id": "firstName",
"placeholder": "First Name"
},
{
"type": "Input.Text",
"id": "lastName",
"placeholder": "Last Name"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"horizontalAlignment": "Left",
"verticalContentAlignment": "Center",
"items": [
{
"type": "TextBlock",
"id": "dobTitle",
"horizontalAlignment": "Right",
"size": "Medium",
"text": "Date of Birth"
}
]
},
{
"type": "Column",
"items": [
{
"type": "Input.Date",
"id": "dob"
}
],
"width": "stretch"
}
]
},
{
"type": "Input.ChoiceSet",
"id": "gender",
"style": "compact",
"placeholder": "Gender",
"choices": [
{
"title": "Female",
"value": "female"
},
{
"title": "Male",
"value": "male"
},
{
"title": "Intersex",
"value": "intersex"
},
{
"title": "Indeterminate",
"value": "indeterminate"
},
{
"title": "Transgender - Female",
"value": "transFemale"
},
{
"title": "Transgender - Male",
"value": "transMale"
},
{
"title": "Other",
"value": "other"
}
]
},
{
"type": "Input.Text",
"id": "street1",
"title": "Street1",
"placeholder": "Street 1"
},
{
"type": "Input.Text",
"id": "city",
"title": "city",
"placeholder": "City"
},
{
"type": "Input.ChoiceSet",
"id": "state",
"style": "compact",
"title": "State",
"placeholder": "State",
"choices": [
{
"title": "SA",
"value": "SA"
},
{
"title": "ACT",
"value": "ACT"
},
{
"title": "NSW",
"value": "NSW"
},
{
"title": "NT",
"value": "NT"
},
{
"title": "QLD",
"value": "QLD"
},
{
"title": "TAS",
"value": "TAS"
},
{
"title": "VIC",
"value": "VIC"
},
{
"title": "WA",
"value": "WA"
},
{
"title": "N/A",
"value": "N/A"
}
]
},
{
"type": "Input.Text",
"id": "postCode",
"title": "PostCode",
"placeholder": "Post Code"
},
{
"type": "Input.Text",
"id": "phone",
"title": "Phone",
"placeholder": "Phone",
"style": "Tel"
},
{
"type": "Input.Text",
"id": "email",
"title": "Email",
"placeholder": "Email",
"style": "Email"
},
{
"type": "Input.ChoiceSet",
"id": "currentAccommodation",
"style": "compact",
"title": "CurrentAccommodation",
"placeholder": "Current Accommodation",
"choices": [
{
"title": "Home",
"value": "home"
},
{
"title": "Hospital",
"value": "hospital"
},
{
"title": "Aged Care",
"value": "agedCare"
},
{
"title": "Other",
"value": "other"
}
]
} ], "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.0"
}发布于 2018-11-14 18:07:35
正如您所提到的,您需要有一个消息端点。我已经在RESTful web服务中使用了适应性卡,但是可以执行HTTP请求的任何web服务都可以。据我所知,从自适应卡发送数据的唯一方法是使用HTTP操作(如果我错了,任何人都可以随时纠正我)。
您将需要查看文档的Actions部分,以了解如何
下面是带有一个简单提交按钮的JSON包的actions部分:
"actions": [
{
"type": "Action.Http",
"id": "Submit",
"title": "Submit",
"method": "POST",
"url": "webserviceURL",
"body": "{\n \"requestId\": \"testapprove\",\n \"callerId\": \"id\",\n \"requestContent\": \"content\",\n \"responseContent\": \"content\"\n}",
"headers": [
{
"name": "content-type",
"value": "\"application/json; charset=utf-8\""
}
]
}
],以下是RESTful web服务的链接:
教程:http://www.drdobbs.com/web-development/restful-web-services-a-tutorial/240169069
在REST上堆叠过低的帖子:什么是RESTful web服务?
您不必在web服务中使用REST,但它正变得相当普遍。谷歌将引导你在创建自己的web服务方面的许多教程。
其他测试选项:
使用网站来接收来自任何人的帖子请求。
这里有一个您可以用来测试的:https://httpbin.org/
另一个:https://docs.postman-echo.com/
如果您只需要在本地发送数据,那么google‘设置本地http服务器’。外面有很多教程。您选择使用的语言可能取决于您的环境和您熟悉的语言。这里是用于python的一种,它将响应get和post请求。这里是另一个python,评论介绍了如何访问发布的信息。
https://stackoverflow.com/questions/53149370
复制相似问题