我正在使用Bot Framework 3.3.0,我理解支持Facebook正确实施的快速回复(而不是创建ChannelData
对象并通过Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply.
发送)。班级名称为var reply = context.MakeMessage();
reply.Text = msg;
var quickReplies = new List<FacebookQuickReply>()
{
new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "Cathay", "Cathay"),
new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "HK Airlines", "Hong Kong Airlines"),
new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "HK Express", "HK Express")
};
以下是我如何在IDialog中创建快速回复:
//I tried both of the lines below
//reply.ChannelData = quickReplies.ToArray();
reply.AddKeyboardCard<FacebookQuickReply>("quick_replies", quickReplies);
await context.PostAsync(reply);
以下是我尝试将其发送到聊天中的两种方式:
FacebookQuickReply
我从Ezequiel Jadib's article得到的第一种方式(嗨,我知道你正在读这篇文章!)在facebook messenger上对我不起作用。部分原因是,在v3.3中,var channelData = new FacebookChannelData();
channelData.QuickReplies = new[]
{
new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "Cathay", "Cathay"),
new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "HK Airlines", "Hong Kong Airlines"),
new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "HK Express", "HK Express")
};
reply.ChannelData = channelData;
类现在已经被密封,无法从中派生出来。
更新:我使用此功能开始工作:
public class FacebookChannelData
{
[JsonProperty("quick_replies")]
public FacebookQuickReply[] QuickReplies { get; set; }
}
FacebookChannelData类只是这样:
"attachments": [
{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"text": "quick_replies",
"buttons": [
{
"type": "imBack",
"title": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply",
"value": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply"
},
{
"type": "imBack",
"title": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply",
"value": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply"
},
{
"type": "imBack",
"title": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply",
"value": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply"
}
]
}
}
],
尽管它有效,但它似乎并不是一种正确的方法,因为僵尸框架现在提供了随时可用的类。
END UPDATE
第二种方式(AddKeyboardCard)在模拟器中有效(但不能在实际的facebook上工作),但产生了我在模拟器中可以看到的完全错误的JSON。生成的JSON使用类名(为什么?)而不是我提供的文本:
FacebookQuickReply
我做错了什么以及如何使用AddKeyboardCard()
和public class Base_HW04Q1
{
public double pi = 3.14, l, radius, height, area, volume;
public static class RoundShape extends Base_HW04Q1 {
public RoundShape(double radius) {
this.radius = radius;
}
public double calcArea () {
area = (radius * radius) * pi;
return area;
}
public String toString() {
return "A Round Shape of radius: " + radius + ", area " + area + ".";
}
}
public static class Cylinder extends Base_HW04Q1
{
public Cylinder(double radius, double height) {
this.radius = radius;
this.height = height;
}
public double calcArea() {
l = Math.sqrt((radius * radius) + (height * height));
area = 2 * pi * radius * height + 2 * pi * l;
return area;
}
public double calcVolume() {
volume = pi * (radius * radius) * height;
return volume;
}
public String toString() {
return "A Cylinder of radius: " + radius + ", area " + area + " and a volume of " + volume;
}
}
public static class Cone extends Base_HW04Q1 //TODO: This line is almost, but not quite, complete.
{
public Cone(double radius, double height) {
this.radius = radius;
this.height = height;
}
public double calcArea() {
l = Math.sqrt((radius * radius) + (height * height));
area = (pi * radius * l) + (pi * radius * radius);
return area;
}
public double calcVolume() {
volume = 0.333 * pi * radius * radius * height;
return volume;
}
public String toString() {
return "A Cone of radius: " + radius + ", area " + area + " and a volume of " + volume;
}
}
public static void main(String[] args)
{
//object creation
Cylinder Cylinder1 = new Cylinder(30, 10);
Cone Cone1 = new Cone(10, 20);
RoundShape RoundShape1 = new RoundShape(50);
//print for objects
System.out.println(Cylinder1);
System.out.println(RoundShape1);
System.out.println(Cone1);
}
}
?
答案 0 :(得分:2)
最近添加的FacebookQuickReply功能的关键在于此commit。
似乎要做的就是创建一个KeyboardCard并使用ToFacebookMessage扩展方法获取ChannelData值(使用here)
答案 1 :(得分:1)
如果您使用的是PromptDialog
,则可以使用以下代码段在Messenger中创建快速回复:
PromptDialog.Choice(
context,
resume,
list of options as strings,
"What do you want to choose?",
retry: "I didn't understand, let's try that again",
attempts: 2,
promptStyle: PromptStyle.Keyboard
);