botpress / v12

Botpress OSS – v12
https://v12.botpress.com
GNU Affero General Public License v3.0
68 stars 83 forks source link

[BUG] Messenger stops working when the botpress server restarts while Facebook app is in live mode #1525

Closed imperialleisure closed 2 years ago

imperialleisure commented 2 years ago

If I restart the botpress server while the Facebook App it is connected to is in Live Mode, Messenger stops receiving messages from the bot but it is still successfully sending messages to the bot.

I see the following error messages repeated in the logs

10/27/2021 11:19:32.395 [Messaging] app:messenger Error trying to setup conduit. Error: Error occured fetching page id
    at MessengerClient.getPageId (/snapshot/messaging/packages/server/dist/channels/messenger/client.js)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

If I put the Facebook app into Development Mode, I see the following success message

[Messaging] app:messenger [botname] Messenger webhook https://[www.website.com]/api/v1/messaging/webhooks/[botname]/messenger`

Turning the Facebook App back into Live Mode no longer shows the error message and Messenger starts working again.

I am running botpress on Ubuntu 18 through docker-compose: docker-compose-community-nginx-https.yaml.

EFF commented 2 years ago

Well noted. Thank you for opening this issue ! We'll try to take a look at this in the upcoming weeks.

refat2090 commented 2 years ago

My app is in development mode but I am also facing the same problem.

samuelmasse commented 2 years ago

@imperialleisure Facebook returns this error message in one of its headers when getPageId fails : OAuth "Facebook Platform" "invalid_request" "(#100) Object does not exist, cannot be loaded due to missing permission or reviewable feature, or does not support this operation. This endpoint requires the 'pages_read_engagement' permission or the 'Page Public Content Access' feature or the 'Page Public Metadata Access' feature. Refer to https://developers.facebook.com/docs/apps/review/login-permissions#manage-pages, https://developers.facebook.com/docs/apps/review/feature#reference-PAGES_ACCESS and https://developers.facebook.com/docs/apps/review/feature#page-public-metadata-access for details.

All three of the proposed solutions mentioned in the error require that an app passes facebook's app review process. An app probably doesn't work at all in live mode until it's reviewed. Are you sure you passed this review before putting your app in live mode?

samuelmasse commented 2 years ago

@refat2090 You need to set the accessToken in your messenger configuration before starting botpress.

imperialleisure commented 2 years ago

@imperialleisure Facebook returns this error message in one of its headers when getPageId fails : OAuth "Facebook Platform" "invalid_request" "(#100) Object does not exist, cannot be loaded due to missing permission or reviewable feature, or does not support this operation. This endpoint requires the 'pages_read_engagement' permission or the 'Page Public Content Access' feature or the 'Page Public Metadata Access' feature. Refer to https://developers.facebook.com/docs/apps/review/login-permissions#manage-pages, https://developers.facebook.com/docs/apps/review/feature#reference-PAGES_ACCESS and https://developers.facebook.com/docs/apps/review/feature#page-public-metadata-access for details.

All three of the proposed solutions mentioned in the error require that an app passes facebook's app review process. An app probably doesn't work at all in live mode until it's reviewed. Are you sure you passed this review before putting your app in live mode?

Thank you for your note. The app has passed the review process and has "Approved: pages_messaging". But sounds like I also need to get Page Public Metadata Access permission. Will try. Thanks.

samuelmasse commented 2 years ago

@imperialleisure There's actually a workaround that I thought about. Fetching the pageId is only something we do to support legacy channel-messenger configurations. With new configurations it doesn't need to be fetched at all. So the messenger channel should work correctly with live apps that don't have permissions in the next botpress release. You can see the fix here : https://github.com/botpress/messaging/pull/227

imperialleisure commented 2 years ago

Thanks for adding that fix! I'm running off of a docker-compose so I might have to change tack and build locally instead.