1
私のFacebookのボットは2200人の加入者を持っていますので、私は以下のコードを使って毎日画像を送信しています。しかし、ボットフレームワークfacebook 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"}}
から取り込んだとして、このコードは、エラーを持つユーザーのほとんどのために失敗している私は、私は1つのメッセージを送信していたときに、それが正常に動作しているため何をすべきかわからないではなく、すべての2200件のメッセージがイマイチ私が10人のためにそれを送るなら、それはうまくいく。主な問題は、テキストは配信されますが、画像は配信されないことです。
を確認したい場合、私はhttps://developers.facebook.com」URLの例からコンテンツタイプを取りました/ docs/messenger-platform/send-api-reference/image-attachment '、これは公開画像です。このコードも少数のユーザーに送信してもうまく動作していますが、何千人ものユーザーにはうまくいきません –
エラーが返されますFacebook APIによって返されています。添付ファイルが有効なURLでない場合、Facebookは一般的にこのエラーを返します。すべてのユーザーにまったく同じことを送信していることは確かですか? – Lars
はい、2200スレッドを作成するのではなく、送信プロセスを遅くすることで問題を解決しました。毎秒10スレッド作成しますが、問題はあるとは思いますが、今は問題ありません –