1

我已經創建了一個帶有微軟殭屍框架的殭屍工具。 所有的工作都很棒。我可以收到併發送消息給信使,但在信使移動推送通知不起作用。我省略了財產notification_type,因爲臉書指南說微軟bot框架和Messanger移動通知

notification_type是可選的;默認情況下,消息將定期 推送通知類型

這是一個框架的bug?

我的代碼:

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); 
+0

您必須確保您的用戶先點擊了「開始使用」按鈕 –

+0

@VũTuấnAnh您可以省略開始對話。否則,用戶alredy點擊開始對話 – Dans

+0

考慮在「您的答案」部分發布您的答案,而不是簡單的問題。 – Lars

回答

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; } 
} 
+0

這裏的關鍵是你必須在你的活動中指定一個ChannelData - 任何ChannelData - 以獲得通知。 – oflahero

1

notification_type是可選的 - 但只有在當你實際上是在你的活動指定ChannelData的情況下。

所以只添加(因爲你是using Newtonsoft.Json.Linq;

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

,你會得到您的通知,前提是您的客戶端應用程序有沒有禁用通知。