A Slack App feature that helps users determine how often a component/element/word was mentioned within Slack messages. The feature provides the user with a number count of the times a specific component is mentioned and referenced.
The project starts off by creating a new Slack App and workspace to build my app. I chose to create a new workspace! Within the application, scopes were used to give the new app permission to do things. Under the OAuth & Permissions tab in the sidebar, add scopes to the app. The scopes that will be necessary include:
channels:read
: This scope allows the app to retrieve a list of all the public channels in a workspace in order to pick one to retrieve a message from.channels:history
: This scope lets the app view all the messages within any public channel in a workspace.
Screen.Recording.2023-10-26.at.2.00.12.AM.mov
- Slack CLI
- Slack Pro Workspace
- Python 3.12.0
- Python Slack SDK 3.23.0
- Slack Signing Secret key
- Bot User OAuth Access Token
In the root directory, create a requirements.txt file and add the following contents to the file.
slack_sdk>=3.0
slack_bolt>=1.6.1
certifi
Install the dependencies by running the following command from terminal.
$ pip3 install -r requirements.txt
Use Certifi's functions to locate installed certificate authority (CA) bundles.
import ssl as ssl_lib
import certifi
ssl_context = ssl_lib.create_default_context(cafile=certifi.where())
The Slack Conversations API provided access to channel-like things within Slack including public and private channels and messages. Using the conversations_history method, I was able to find all the messages. From there, the text was converted into strings and stored in an array with single-word strings.
![Screenshot 2023-10-26 at 3 31 02 AM](https://private-user-images.githubusercontent.com/31296177/278300328-355ff60f-ad8b-4655-b7ed-41d73f7f621f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1ODgyODEsIm5iZiI6MTcyNDU4Nzk4MSwicGF0aCI6Ii8zMTI5NjE3Ny8yNzgzMDAzMjgtMzU1ZmY2MGYtYWQ4Yi00NjU1LWI3ZWQtNDFkNzNmN2Y2MjFmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDEyMTMwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQxMTBmNzA0MmYwMDBlYWVmN2Y2NDdjZDYxMzJmNWFiZDU2YjMzZDkzNWQwM2RkNmE4MmI5ZjIyMzA5ZGVmNDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.AEmLSnGH0frqejsj3dW-BDWYhKafWtTY-ldTg91ik0I)
Clone the repository
$ git clone https://github.com/debbieyuen/slack-app-mentions.git
Install Slack CLI (Mac)
# Run the automated installer from your terminal window:
$ curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash
# Authorize the CLI in your workspace with the following command:
$ slack login
# Input an entry for a paid workspace
$ slack auth list
Retrieve your Bot User OAuth Access Token for your app from the app management page. In your terminal, add your token to your environment variables.
$ export SLACK_BOT_TOKEN='xoxb-XXXXXXXXXXXX-xxxxxxxxxxxx-XXXXXXXXXXXXXXXXXXXXXXXX'
![Screenshot 2023-10-26 at 2 57 37 AM](https://private-user-images.githubusercontent.com/31296177/278290989-987ea01d-b587-478d-a482-45d7e5530e14.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1ODgyODEsIm5iZiI6MTcyNDU4Nzk4MSwicGF0aCI6Ii8zMTI5NjE3Ny8yNzgyOTA5ODktOTg3ZWEwMWQtYjU4Ny00NzhkLWE0ODItNDVkN2U1NTMwZTE0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDEyMTMwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTlmMjNiMTA2NjhlZTY0Mjc1ZjQ3NWJmN2Q4ODUxNmU1NGYzYTUzNTQ3NDU3MmQwYjcwNTI5YjI3ZDhiNDRmMGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.5jDT39GiKZkMNfZoqLbbQQAq7_kmBb6LewA3oPDNfNc)
Retrieve your Slack Signing Secret key for your app from the app management page. In your terminal, run the following command.
$ export SLACK_SIGNING_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
![Screenshot 2023-10-26 at 3 01 21 AM](https://private-user-images.githubusercontent.com/31296177/278292060-61d43a85-5fc8-4216-9543-8b101b483f20.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1ODgyODEsIm5iZiI6MTcyNDU4Nzk4MSwicGF0aCI6Ii8zMTI5NjE3Ny8yNzgyOTIwNjAtNjFkNDNhODUtNWZjOC00MjE2LTk1NDMtOGIxMDFiNDgzZjIwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDEyMTMwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThmYmYzNWEyM2EzYTQwNzQ5Yjc1NmQ4MGJlMmY4ZGZlOWJjOGJlZGI2OGYyYjFkMTBhNzk4OGEyNGIyM2ZkY2ImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.77Gy-WPr4246eEhxr6iyK2EAdH-2PYmUFrr_IaRompw)
Run the python file
$ python3 bot.py
On the app management page, install the DebBot app in your workspace. Then, in Slack add the DeBot app to the #general
channel.
![Screenshot 2023-10-26 at 3 06 19 AM](https://private-user-images.githubusercontent.com/31296177/278293372-b6977381-5489-4bf4-9660-3992fa9d1cdc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1ODgyODEsIm5iZiI6MTcyNDU4Nzk4MSwicGF0aCI6Ii8zMTI5NjE3Ny8yNzgyOTMzNzItYjY5NzczODEtNTQ4OS00YmY0LTk2NjAtMzk5MmZhOWQxY2RjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDEyMTMwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThjZWIwMGQxNTg5N2Q3ZGFkN2VhMTZhNjY0OGJjOWIxZDgyMTY1MWI4YzMxM2JiYjM0ZjgyYmZmM2I2MGQ4N2EmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.dRKdH6fY5yVLDB2APxjAj4ftm8emPye-t1wdrNAJ9BQ)
- Python Slack SDK Documentation
- @karishay's PythOnBoardingBot tutorial
- The New Slack Platform YouTube series
- Slack: Retrieving Messages
- Slack: Conversations API
- Slack: Using the Slack Web API