Search code examples
pythonwebhooksslack

How to export Slack messages to Python


I've been trying to use outgoing webhook in Slack to export messages from the channel to my Python program but I can't find the way to do it, so I wonder if even a thing like this exists?


Solution

  • Slack seems to have an API you can use to retreive the messages of a given channel. Follow this link : https://api.slack.com/messaging/retrieving

    You can make a GET request to retreive the full history of the given conversation (so all the messages) :

    GET https://slack.com/api/conversations.history?token=YOUR_TOKEN_HERE&channel=CONVERSATION_ID_HERE
    Content-type: application/json
    

    You can easily make GET requests wiht python using the library called 'requests'. If you're able to have a valid API token and the ID of the conversation, you will then be able to get all the messages of the chosen conversation.