2016-11-22 52 views
1

我的臉譜機器人有2200用戶,所以我使用下面的代碼每天向他們發送圖像。然而,這個代碼是沒有的最有錯誤的用戶從BOT框架臉譜機器人無法從URL獲取文件

public static class MessagesSender 
{ 
    public static void SendSpecificMessage(string botName, string serviceURL, string botId, string messageCode, string messageText, string imageURL, Customer customer , Guid logId) 
    { 
     var connector = new ConnectorClient(new Uri(serviceURL)); 

     Thread thread = new Thread(() => SendMessage(botName, serviceURL, botId, messageCode, messageText, imageURL, customer, connector , logId)); 
     thread.Start(); 

    } 

    private static void SendMessage(string botName, string serviceURL, string botId, string messageCode, string messageText, string imageURL, Customer customer, ConnectorClient connector , Guid logId) 
    { 


     try 
     { 


     Task.Run(async() => 
     { 
      IMessageActivity message = Activity.CreateMessageActivity(); 
      //defining accounts 
      var userAccount = new ChannelAccount(name: customer.name, id: customer.fromidstate); 
      var botAccount = new ChannelAccount(name: botName, id: botId); 

      //creating conversation 
      var conversationId = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount); 


      message.From = botAccount; 
      message.Recipient = userAccount; 



      message.Text = "Daily Image"; 
      message.Conversation = new ConversationAccount(id: conversationId.Id.Replace("@", string.Empty)); 



      if (!string.IsNullOrEmpty(imageURL)) 
      { 
       message.Attachments = new List<Attachment>(); 
       message.Attachments.Add(new Attachment() 
       { 
        ContentUrl = imageURL, 
        ContentType = "image" 
       }); 
      } 




      await connector.Conversations.SendToConversationAsync((Activity)message); 



     }).Wait(); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 

     } 
    } 
} 

{"error":{"message":"(#100) Failed to fetch the file from the url","type":"OAuthException","code":100,"error_subcode":2018008,"fbtrace_id":"G8ZFKZLCmNp"}} 

捕捉我不知道該怎麼做,因爲當我發送一個消息,它的正常工作,但不是所有的2200個訊息心不是交付,如果我送它10人就沒事了。並且主要問題是文本被傳遞但不是圖像

+0

我把內容類型從示例中的URL(「613」)「https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment',是的,它是公開的圖像,這個代碼也可以很好地發送給少數用戶,它只是不適用於數千用戶 –

+0

錯誤被返回給你正在由Facebook API返回。當附件不是有效的URL時,Facebook通常會返回此錯誤。你確定你發送給所有用戶完全一樣的東西嗎? – Lars

+0

是的,我通過減慢發送進程來解決這個問題,而不是創建2200個線程,我每秒創建10個線程,儘管我不確定這是一個問題,但現在情況很好 –

回答

1

錯誤被Facebook API返回。看起來你正在達到限制限制。解決方法是減慢發送圖像的速度。

您可以檢查錯誤的返回代碼,如果您想確認

Facebook error codes