slackapi / bolt-python

A framework to build Slack apps using Python
https://slack.dev/bolt-python/
MIT License
1.03k stars 237 forks source link

FastAPI & sqlalchemy - Your installation with this app is no longer available #1030

Closed kadosh1000 closed 5 months ago

kadosh1000 commented 5 months ago

I am trying to use bolt-python asyncly using FastAPI and sqlalchemy (using Postgres). I basically took this sqlalchemy example and just replaced Sanic with FastAPI.

Installation and redirect works well, and I also see the installations being added to Postgres, and I can also see events coming in through ngrok. But the events are not being processed and instead I get the message:

We apologize, but for some unknown reason, your installation with this app is no longer available. Please reinstall this app into your workspace.

I tried reinstalling the app to the workspace multiple times, but I still continue to get this error.

I also tried debugging the AsyncInstallationStore and it seems that the async_find_bot function never triggers, so I am not sure where exactly to look why its not getting there.

Edit: After some more digging into the code, it seems to be probably related to the AsyncInstallationStoreAuthorize. It looks like it is trying to use async_find_installation even though it was not implemented by my installation store, probably because it is extending AsyncInstallationStoreclass. Anyway to go around it?

Reproducible in:

The slack_bolt version

slack-bolt==1.18.1 slack_sdk==3.27.0

Python runtime version

3.10.12

OS info

ProductName: macOS ProductVersion: 13.4.1 ProductVersionExtra: (c) BuildVersion: 22F770820d Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64

Steps to reproduce:

  1. Copy the sqlalchemy example
  2. Replace Sanic with FastAPI
  3. Set relevant environment variables (Client ID, Client Secret, Signing Secret)
  4. Install the app to your slack workspace using /slack/install
  5. Send a message to the bot on Slack

Expected result:

The event should go through the request handler and trigger the relevant event handle (i.e @app.event("message"))

Actual result:

When an event is being sent to the app using POST /slack/events, it responds with 200 with the message:

We apologize, but for some unknown reason, your installation with this app is no longer available. Please reinstall this app into your workspace.

image

Also I can see this error in my console: Although the app should be installed into this workspace, the AuthorizeResult (returned value from authorize) for it was not found.

kadosh1000 commented 5 months ago

Ok, so I found the issue and the steps to fix it. There were 2 issues with just copy-pasting the example:

  1. if using the find_bot function instead of find_installlation then you should put to the app properties installation_store_bot_only=True

  2. Apparently there was an exception thrown because my implementation of AsyncInstallationStore:async_find_bot function, did not have the is_enterprise_install optional parameter. So the function signature will look like: async def async_find_bot( self, *, enterprise_id: Optional[str], team_id: Optional[str], is_enterprise_install: Optional[bool] ) -> Optional[Bot]:

I recommend to update the examples using custom AsyncInstallationStore

seratch commented 4 months ago

Thank you so much for reporting the issue, and we're sorry for the disruption you encountered. I just updated the example code to resolve it.