Bot Framework未收到Facebook Messenger Referral事件,询问是否支持
Yes, Bot Framework does support Facebook Messenger's Referral events—let’s walk through the common issues that might be preventing you from receiving them, since you’ve already confirmed permissions and routing via nGrok.
Key Checks to Troubleshoot:
Verify Referral Trigger Format
Them.melink must include arefparameter to trigger the event, like:http://m.me/YourPageName?ref=your_custom_valueWithout the
refparameter, Facebook won’t send a Referral event at all. Double-check your link structure to ensure it’s correctly formatted.Confirm Webhook Event Subscription
Even if you’ve granted permissions in Facebook’s app settings, you need to explicitly subscribe to themessaging_referralsevent in your Bot Framework’s Facebook channel configuration:- Go to your Azure Bot resource → Channels → Select Facebook Messenger → Edit
- Under "Webhook Subscriptions", ensure
messaging_referralsis checked - Save the configuration and re-authenticate the channel if needed
Check Your Bot’s Event Handling Logic
Bot Framework wraps Facebook’s Referral event into anEventActivitywith the namefacebook_referral. Make sure your code is listening for this specific event type:- For C# SDK:
protected override async Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken) { if (turnContext.Activity.Name == "facebook_referral") { // Access referral data from the activity's Value property var referralData = turnContext.Activity.Value as JObject; // Add your referral handling logic here } await base.OnEventActivityAsync(turnContext, cancellationToken); } - For JavaScript SDK:
this.onEvent(async (context, next) => { if (context.activity.name === 'facebook_referral') { const referralData = context.activity.value; // Process the referral data as needed } await next(); });
- For C# SDK:
Inspect nGrok Request Details
While you see messages routing to your bot, dig into the raw POST requests in nGrok to confirm if Facebook is actually sending the Referral event:- Look for requests where the payload includes
entry[0].messaging[0].referral - If this payload isn’t present, the issue lies with Facebook’s event triggering (double-check your page settings or link validity)
- If the payload is present but your bot isn’t receiving it, check Azure Monitor logs for your Bot resource to see if the event is being filtered or dropped
- Look for requests where the payload includes
Test with Facebook’s Graph API Explorer
To isolate the issue, manually send a Referral event to your webhook using the Graph API:- Use the
POST /{page-id}/messagesendpoint with a payload like:{ "recipient": {"id": "USER_ID"}, "referral": {"ref": "test_ref", "source": "SHORTLINK", "type": "OPEN_THREAD"} }
If your bot receives this test event, the problem is with how your
m.melink is configured; if not, there’s likely an issue with your Bot Framework channel setup or event handling code.- Use the
Final Notes
If all checks pass and you still don’t receive the event, consider updating your Bot Framework SDK to the latest version—older versions may have compatibility issues with newer Facebook Messenger features.
内容的提问来源于stack exchange,提问作者NiteLordz

