chatwoot / chatwoot

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬
https://www.chatwoot.com/help-center
Other
20.59k stars 3.38k forks source link

Fetching only 25 Facebook Pages #3082

Open GKG4 opened 3 years ago

GKG4 commented 3 years ago

I have more than 40 Facebook pages, however, the self hosted version is fetching only first 25 pages. Is there any way to edit .env variable to set it to higher number?

GKG4 commented 2 years ago

Any update on this small query, its no big deal to solve, just need to add LIMIT {variable}

pranavrajs commented 2 years ago

@GKG4 We didn't have a chance to test it out. We will check it out and see if we can reproduce the error.

If you are comfortable with sending a Pull Request, please feel free to do it. We are happy to guide you.

GKG4 commented 2 years ago

You cant reproduce as its not an error, its about default limit of fetching FB Pages. Its fetching 25 pages only, and I have 40+ pages, therefore, you need to extend FB fetch code to increase this limit.

sojan-official commented 2 years ago

@GKG4 its not configurable via a variable. I think we would need to paginate through all the available pages for that account than stopping after the single API call

ref: https://github.com/chatwoot/chatwoot/blob/1761bec6152b3c7dedf0c97da4e6468914d7e881/app/controllers/api/v1/accounts/callbacks_controller.rb#L22

GKG4 commented 2 years ago

Apart from paginate, there is an option to set limit while querying, as per the Facebook Graph Explorer. You simply need to add Limit(100) or whatever number of pages you need to fetch, this will fetch in a single call without pagination.

GKG4 commented 2 years ago

@page_details = mark_already_existing_facebook_pages(fb_object.get_connections('me', 'accounts'))

if we change it to

@page_details = mark_already_existing_facebook_pages(fb_object.get_connections('me', 'accounts.limit(100)'))

it should work, however, since I am .net developer, I cannot compile or run this code. If you can test it, much appreciated.

GKG4 commented 2 years ago

@sojan-official Is there any chance that you will be fixing this issue? Because this is the only thing stopping me from using ChatWoot at the moment

I have few suggestions and if you are willing to discuss a bit, I am more than happy to contribute Open Source Windows version for Chatwoot, and probably Mac Version too.

sojan-official commented 2 years ago

@GKG4 Yes, We will be prioritizing it for our next week's issue intake.

We are always open to feedback. Please feel free to initiate a GitHub discussion/issue anytime for anything :) We are also available on discord: https://discord.gg/cJXdrwS

tejaswinichile commented 2 years ago

@GKG4 We don't restrict the number of Facebook pages in chatwoot. It's not related to the pagination or limit.

fb_object.get_connections('me', 'accounts') = returns all the pages connected your account, this is the command that we run and send it to facebook to get the connected pages.

The issue might be with the access permission that your account has to the other pages. https://developers.facebook.com/docs/facebook-login/permissions/overview/#granularpermissions

If you have configured this on the self-hosted version, and you have access to https://developers.facebook.com/tools/explorer/ then you can run the query me/accounts and check the connected pages to the account like below.

Screenshot 2021-10-04 at 6 28 15 PM

Or you can go to https://business.facebook.com/latest/settings/business_assets to check the pages to which you have access.

cc @sojan-official

GKG4 commented 2 years ago

@tejaswinichile and @sojan-official

Its not you who is putting the restrictions. Its that if you do not set fetch limit, default number of pages FB send is 25. You need to provide either pagination or option to call more than 25 pages by adding limit variable into the queries.

I already have a custom app built in .net fetching all 40+ pages, therefore, I know that I have access to those pages.

As you can see the first screenshot, when I called /me/accounts

1

You will see the pagination at the end, however, when I called me?fields=accounts.limit(100) 2

There is no pagination. The error is not from your end, but its a limit from Facebook.

Hope I cleared my point here.

GKG4 commented 2 years ago

@sojan-official @tejaswinichile @pranavrajs

For the time being, I have a fix for this.

I noted the first 25 pages FB is sending, and then while Authorizing the app with ChatWoot, I deselected those first 25 pages, this way I got the remaining 15 pages (out of 40).

Then I added Inbox for those pages, one by one, and once the list was empty while Authorizing with Facebook, I edited the settings and authorized the remaining 25 pages. This way, I got all 40 pages in my ChatWoot. I know its not a solution but a workaround for the time being.

Cheers!!!

sojan-official commented 2 years ago

@GKG4 Thanks for posting back. Nice Hack. We will prioritize a proper fix :)

GKG4 commented 2 years ago

@sojan-official As of now, we have 24 hours window to reply, after that we cant reply to FB Messages However, Facebook to give option for 7 days window, if we use HUMAN_AGENT tag

Is it possible, if you guide me, where I can add all these, I am willing to contribute? Also, I am willing to add different message templates as per Facebook API

sojan-official commented 2 years ago

@GKG4 I guess we need to append the human tag params to the message payload here

ref: https://github.com/chatwoot/chatwoot/blob/c54aae21ff8f21db3a8be45c44bc1dfda2798f0c/app/services/facebook/send_on_facebook_service.rb#L22

ref: https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags/

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient": { 
    "id": "<PSID>"
  },
  "message":{
    ...
  },
  "messaging_type": "MESSAGE_TAG",
  "tag": "ACCOUNT_UPDATE"

}' "https://graph.facebook.com/v12.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>"  

But we would need to assess and do the following

would be happy to collaborate over a PR

GKG4 commented 2 years ago

@sojan-official Since HUMAN_AGENT do not require any additional permission, and since Chatwoot is usually human operated only, we can make it defafult as well.

sojan-official commented 2 years ago

@GKG4 "Human Agent permission is not available in standard access/dev mode. You will need to complete the app review process before you can leverage the human agent tag. During app review submission, please provide clear instructions and demo on how you intend to leverage the human agent tag in your experiences."

ref: https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags/ I think we need to consider our community installations that run Facebook apps without going through the app review submission, using dev mode.

mredodos commented 11 months ago

some news?