chatwoot icon indicating copy to clipboard operation
chatwoot copied to clipboard

fix: Creates contact when Instagram returns `No matching Instagram user`

Open victoreduardo opened this issue 11 months ago • 4 comments

Creates contact when Instagram returns No matching Instagram user

Description

The error occurs when Facebook tries to validate the Facebook App created to authorize Instagram integration. The Facebook's agent uses a Bot to make tests on the App where is not a valid user via API, returning {"error"=>{"message"=>"No matching Instagram user", "type"=>"IGApiException", "code"=>9010}}. Then Facebook rejects the request saying this app is still not ready once the integration with Instagram didn't work. We can safely create an unknown contact, making this integration work.

Type of change

Please delete options that are not relevant.

  • [X] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • [ ] This change requires a documentation update

How Has This Been Tested?

There's automated test to cover.

Checklist:

  • [X] My code follows the style guidelines of this project
  • [X] I have performed a self-review of my code
  • [X] I have commented on my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] My changes generate no new warnings
  • [X] I have added tests that prove my fix is effective or that my feature works
  • [X] New and existing unit tests pass locally with my changes
  • [ ] Any dependent changes have been merged and published in downstream modules

victoreduardo avatar May 16 '25 14:05 victoreduardo

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: app/services/instagram/message_text.rb

Function Unhandled Issue
fetch_instagram_user [**NameError: undefined local variable or method error' for an instance of Instagram::MessageText (NameError)**](https://chatwoot-p3.sentry.io/issues/6606852567/?referrer=github-open-pr-bot) ... <br> Event Count:` 8

Did you find this useful? React with a 👍 or 👎

sentry[bot] avatar May 16 '25 14:05 sentry[bot]

@victoreduardo Thanks for the PR.

@muhsin-k Please validate the bug and see if the fix is relevant.

pranavrajs avatar May 16 '25 15:05 pranavrajs

@victoreduardo Thanks for the PR. We would like to know more about the problem you are trying to solve.

  • Are you trying to configure the Instagram inbox using business login: https://www.chatwoot.com/docs/self-hosted/configuration/features/integrations/instagram-via-instagram-business-login
  • Is there any way to replicate this issue?
  • Is this documented somewhere? Please provide links to the documentation for this behavior.

muhsin-k avatar May 26 '25 08:05 muhsin-k

hey @muhsin-k! Yes, i'm trying to set up follow that guide. There's no documentation on Facebook side about this behavior. I found this behavior after getting 2 rejections. Then i got some logs and found this error. i could see that the chat was with a kind of bot. After my fix, my app request was approved. i also saw the same behavior after approving my request where the unknown contact was created.

victoreduardo avatar Jun 02 '25 14:06 victoreduardo

@victoreduardo Thanks for the fix. However, the changes need to be applied to the Instagram Messenger service as well. Can you please apply the same logic to handle error code 9010 https://github.com/chatwoot/chatwoot/blob/develop/app/services/instagram/messenger/message_text.rb#L26.

Also, have you been able to reproduce these cases locally somehow?

muhsin-k avatar Jul 02 '25 08:07 muhsin-k

@victoreduardo Thanks for the fix. However, the changes need to be applied to the Instagram Messenger service as well. Can you please apply the same logic to handle error code 9010 https://github.com/chatwoot/chatwoot/blob/develop/app/services/instagram/messenger/message_text.rb#L26.

Also, have you been able to reproduce these cases locally somehow?

Hey @muhsin-k, after i made this change i was able to get approval from meta, as i said. I can change that second file as well. I'm not able to repro locally since it only happens when meta is validating the app. I got this case analyzing the logs after many rejections.

victoreduardo avatar Jul 03 '25 11:07 victoreduardo

@victoreduardo Thanks for the fix. However, the changes need to be applied to the Instagram Messenger service as well. Can you please apply the same logic to handle error code 9010 https://github.com/chatwoot/chatwoot/blob/develop/app/services/instagram/messenger/message_text.rb#L26. Also, have you been able to reproduce these cases locally somehow?

Hey @muhsin-k, after i made this change i was able to get approval from meta, as i said. I can change that second file as well. I'm not able to repro locally since it only happens when meta is validating the app. I got this case analyzing the logs after many rejections.

@victoreduardo We'll test this and merge it after you make the changes.

muhsin-k avatar Jul 03 '25 14:07 muhsin-k