Chainlit / docs

9 stars 59 forks source link

Warn against in-app setting of Slack environment variables #153

Open allihaider opened 1 week ago

allihaider commented 1 week ago

The current documentation doesn't explicitly warn against setting SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET environment variables within the application code. This can lead to unexpected behavior where the Slack integration fails to work properly.

When the Slack endpoints are being added in the server setup file (chainlit/backend/chainlit/server.py), the following code is executed:

# -------------------------------------------------------------------------------
#                               SLACK HANDLER
# -------------------------------------------------------------------------------
if os.environ.get("SLACK_BOT_TOKEN") and os.environ.get("SLACK_SIGNING_SECRET"):
    from chainlit.slack.app import slack_app_handler
    @router.post("/slack/events")
    async def slack_endpoint(req: Request):
        return await slack_app_handler.handle(req)

At this point, the user's application script has not yet run. Consequently, if the environment variables are set within the user's code, they won't be available when this check is performed. This results in the Slack endpoints not being added to the server, causing the Slack integration to fail.

This PR updates the documentation to clearly state that SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET must be set externally to the application code.