我正在尝试向Facebook上的所有用户发送消息,但是有30%的用户因此错误而失败
System.AggregateException: One or more errors occurred. --->
System.UnauthorizedAccessException: Authorization for Microsoft App ID ****
failed with status code Forbidden
at Microsoft.Bot.Connector.JwtTokenRefresher.<SendAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
这是我的代码,70%的消息代码正常运行但是它失败了30%,我确信30%没有阻止机器人或其他东西
MicrosoftAppCredentials.TrustServiceUrl(serviceURL, DateTime.Now.AddDays(7));
var account = new MicrosoftAppCredentials(WebConfigurationManager.AppSettings["MicrosoftAppId"], WebConfigurationManager.AppSettings["MicrosoftAppPassword"]);
var connector = new ConnectorClient(new Uri(serviceURL), account);
try
{
msg.customerid = customerIdGuid;
msg.subscriptionmessagelogid = logId;
msg.messagecode = messageCode;
msg.creationdate = DateTime.UtcNow;
if (!string.IsNullOrEmpty(messageText))
{
Task.Run(async () =>
{
IMessageActivity message = Activity.CreateMessageActivity();
message.Text = messageText;
if (messageButton != null)
{
message.Attachments = new List<Microsoft.Bot.Connector.Attachment>();
message.Attachments.Add(messageButton);
}
//defining accounts
var userAccount = new ChannelAccount(name: customerName, id: customerId);
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.Conversation = new ConversationAccount(id: conversationId.Id.Replace("@", string.Empty));
await connector.Conversations.SendToConversationAsync((Activity)message);
}).Wait();
}
}