slack-api

Detect image added by user in channel


I want to make a Slack App that works with images provided by the users of the channel. For discussion sake, let's say a user drops a picture, my app would detect the picture, upload it to my backend server, then analyze the image and respond with some text to the user.

How do I go about detecting that a user has dropped an image into a channel that my app is watching?

Is there an example I can read somewhere?


Solution

  • Turns out, if using the python Bolt framework, this is pretty trivial. Follow this example: https://slack.dev/bolt-python/tutorial/getting-started

    Then add a handler for 'file_shared' like so:

    @app.event("file_shared")
    def handle_file_shared_events(body, logger, client: WebClient, context):
        ....
    

    You'll need to add Oath permissions for 'files:read'.