1

我已经为 Messenger 创建了一个带有 Microsoft 机器人框架的机器人。一切都很好。我可以接收消息并将消息发送给 messanger,但在 messanger 移动推送通知中不起作用。我省略了属性 notification_type 因为 facebook 指南说

notification_type 是可选的;默认情况下,消息将是常规推送通知类型

这是一个框架错误?

我的代码:

ConnectorClient connector = new ConnectorClient(new Uri(servUri), microsoftAppId: appId, microsoftAppPassword: pass);
ResourceResponse conversationId = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);
IMessageActivity activity = Activity.CreateMessageActivity();

activity.Id = conversationId.Id;
activity.Type = ActivityTypes.Message;
activity.From = botAccount;
activity.Conversation = conversation;
activity.Recipient = userAccount;
activity.Text = "hello";

await connector.Conversations.SendToConversationAsync((Activity)activity);
4

2 回答 2

1

notification_type是可选的 - 但仅在您实际在活动中指定 ChannelData 的情况下。

所以只需添加(假设你是using Newtonsoft.Json.Linq;

        activity.ChannelData = JObject.FromObject(new
        {
            notification_type = "REGULAR"
        });

只要您的客户端应用程序没有禁用通知,您就会收到通知。

于 2017-10-06T14:02:23.327 回答
1

我使用了 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; }
}
于 2017-01-18T23:36:43.180 回答