我使用了 activity.ChannelData 并且所有工作都很好我发布了我的解决方案,可能对某人有用
将附件添加到活动中:
activity.ChannelData = new FacebookChannelData()
{
Attachment = GetFacebookAttachment()
};
创建附件:
private static FacebookAttachment GetFacebookAttachment()
{
return new FacebookAttachment()
{
Payload = new GenericTemplate
{
Elements = new[] {
new TemplateElements(){
Title = "my title",
ItemUrl = "https://example.com",
ImageUrl = "https://example.com/test.jpg",
Subtitle = "subtitle",
Buttons = new[] {
new TemplateButtons() {
Type = "web_url",
Url = "https://example.com",
Title = "button title"
}
}
}
}
}
};
}
然后是课程:
public class FacebookChannelData
{
public FacebookChannelData() {
this.NotificationType = "REGULAR";
}
[JsonProperty("notification_type")]
public string NotificationType { get; set; }
[JsonProperty("attachment")]
public FacebookAttachment Attachment { get; internal set; }
}
public class FacebookAttachment
{
public FacebookAttachment()
{
this.Type = "template";
}
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("payload")]
public dynamic Payload { get; set; }
public override string ToString()
{
return this.Payload.ToString();
}
}
public class GenericTemplate
{
public GenericTemplate()
{
this.TemplateType = "generic";
}
[JsonProperty("template_type")]
public string TemplateType { get; set; }
[JsonProperty("elements")]
public TemplateElements[] Elements { get; set; }
}
public class TemplateElements
{
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("item_url")]
public string ItemUrl { get; set; }
[JsonProperty("image_url")]
public string ImageUrl { get; set; }
[JsonProperty("subtitle")]
public string Subtitle { get; set; }
[JsonProperty("buttons")]
public TemplateButtons[] Buttons { get; set; }
}
public class TemplateButtons
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("payload")]
public string Payload { get; set; }
}