Skip to content

Commit

Permalink
Fix the currently broken facebook connector (#1989)
Browse files Browse the repository at this point in the history
* Fix facebook connector not working likely due to API updates

* How to avoid "No matching user found" error

* Fix linting

---------

Co-authored-by: Jacob Tomlinson <jacob@tomlinson.email>
  • Loading branch information
plantroon and jacobtomlinson committed Apr 25, 2024
1 parent 1e8c376 commit e69b463
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/connectors/facebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Follow the steps to get access token :
- Once the app is created, go to app’s Settings, and under PRODUCTS, click Add Product. Select Messenger, and choose to Set up the messenger product.
- Generate a `page-access-token` for the page you created to start using Facebook APIs
- Create a webhook pointing to `http(s)://your-bot-url.com:port/connector/facebook`
- Subscribe to all events for the webhook except for message_echoes to avoid an error like `{"error":{"message":"(#100) No matching user found","type":"OAuthException"...`
- Randomly generate a `verify-token` and add that to the webhook

## Configuration
Expand Down
11 changes: 6 additions & 5 deletions opsdroid/connector/facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from opsdroid.events import Message

_LOGGER = logging.getLogger(__name__)
_FACEBOOK_SEND_URL = "https://graph.facebook.com/v2.6/me/messages" "?access_token={}"
_FACEBOOK_SEND_URL = "https://graph.facebook.com/v16.0/me/messages" "?access_token={}"
CONFIG_SCHEMA = {
Required("verify-token"): str,
Required("page-access-token"): str,
Expand Down Expand Up @@ -73,10 +73,11 @@ async def facebook_message_handler(self, request):
_LOGGER.debug(fb_msg)
try:
message = Message(
fb_msg["sender"]["id"],
fb_msg["sender"]["id"],
self,
fb_msg["message"]["text"],
text=fb_msg["message"]["text"],
user=fb_msg["sender"]["id"],
user_id=fb_msg["sender"]["id"],
target=fb_msg["sender"]["id"],
connector=self,
)
await self.opsdroid.parse(message)
except KeyError as error:
Expand Down

0 comments on commit e69b463

Please sign in to comment.