我的用例是能够使用Facebook Dev Docs中描述的消息标签在 Facebook 的 24 + 1 政策之外发送消息。它指出我需要设置messing_type 和一个有效的 tag。我已经设置了 messing_type 但无法让标签工作。
目前我从 Facebook 收到此错误:
{
"error": {
"message": "(#100) Tag is required for MESSAGE_TAG messaging type.",
"type": "OAuthException",
"code": 100,
"error_subcode": 2018199,
"fbtrace_id": "GvmKwSrcqVb"
}
}
对我来说,这表明我已经成功设置了 messing_type 但没有设置标签。我已经尝试在活动中添加其他建议GitHub #2924中的标签。如下所示的属性,但它不起作用,所以我也在 ChannelData 中尝试过它也不起作用。
activity.Properties = new Newtonsoft.Json.Linq.JObject();
activity.Properties.Add("tag", "CONFIRMED_EVENT_REMINDER");
activity.ChannelData = JObject.FromObject(new
{
messaging_type = "MESSAGE_TAG",
tag = "CONFIRMED_EVENT_REMINDER"
});
任何帮助将不胜感激,因为这似乎很接近工作,但同时确实限制了我的机器人的能力。
我已经在 GitHub 上交叉发布了这个。
谢谢
编辑 - 下面添加的代码示例
这是我的代码,在所有普通情况下都能正常工作,但我无法使用消息标签在 Facebook 24 + 1 规则之外发送消息。其他一些信息是我已经在机器人框架门户上迁移了我的机器人,它在 Facebook Messenger 上运行,我的 pages_messaging 已获得批准,但尚未申请 pages_messaging_subscriptions。
[RoutePrefix("api/outboundtest")]
public class SendBotMessageTestController : ApiController
{
[HttpPost]
[Route("SendSimpleMessage")]
public async Task<HttpResponseMessage> SendSimpleMessage([FromBody] BotToCustomerMessageTestDTO dto)
{
try
{
var conversationRef = JsonConvert.DeserializeObject<ConversationReference>(dto.BotConversationJson);
// We need to ensure the URL is trusted as we lose this from the in-memory cache of trusted URLs if/when the app pool recycles: https://github.com/Microsoft/BotBuilder/issues/1645
MicrosoftAppCredentials.TrustServiceUrl(conversationRef.ServiceUrl);
var activity = conversationRef.GetPostToBotMessage();
var userAccount = new ChannelAccount(conversationRef.User.Id, conversationRef.User.Name);
var botAccount = new ChannelAccount(conversationRef.Bot.Id, conversationRef.Bot.Name);
activity.ChannelId = conversationRef.ChannelId;
activity.From = botAccount;
activity.Recipient = userAccount;
activity.Conversation = new ConversationAccount(id: conversationRef.Conversation.Id);
activity.Locale = "en-Gb";
var connector = new ConnectorClient(new Uri(conversationRef.ServiceUrl), this.GetCredentials());
if (activity.ChannelId == "facebook")
{
// Add TAG indicate we can send this message outside the allowed window as suggested here: https://github.com/Microsoft/BotBuilder/issues/2924
activity.Properties = new Newtonsoft.Json.Linq.JObject();
activity.Properties.Add("tag", "CONFIRMED_EVENT_REMINDER");
// Set messaging_type as suggested here: https://github.com/Microsoft/BotBuilder/issues/4154 and https://developers.facebook.com/docs/messenger-platform/reference/send-api/
activity.ChannelData = JObject.FromObject(new
{
notification_type = "REGULAR",
messaging_type = "MESSAGE_TAG"
});
}
// Send the message:
activity.Text = dto.Message;
await connector.Conversations.SendToConversationAsync((Activity)activity).ConfigureAwait(false);
var resp = new HttpResponseMessage(HttpStatusCode.OK);
resp.Content = new StringContent($"Message sent", System.Text.Encoding.UTF8, @"text/plain");
return resp;
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
private MicrosoftAppCredentials GetCredentials()
{
return new MicrosoftAppCredentials("ABC", "XYZ");
}
}
public class BotToCustomerMessageTestDTO
{
public string BotConversationJson; // Stored from previous reply using activity.ToConversationReference()
public string Message; // This is the message to send.
}