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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc4NDM1MTAsIm5iZiI6MTcxNzg0MzIxMCwicGF0aCI6Ii8zMTI5NjE3Ny8yNzgzMDAzMjgtMzU1ZmY2MGYtYWQ4Yi00NjU1LWI3ZWQtNDFkNzNmN2Y2MjFmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjA4VDEwNDAxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk3YTgzZjQxZDFmZDBhYWJhYTI1N2YzN2NjYzEyMmVmYzRlZjI2MDhmN2NkNzQxYTBjNTc2YjQ3Y2UzMmJmNDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.tlT9qPhrSUFuJbFgQobjOJ90AxLb0dn4r7P9i01vw_I)
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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc4NDM1MTAsIm5iZiI6MTcxNzg0MzIxMCwicGF0aCI6Ii8zMTI5NjE3Ny8yNzgyOTA5ODktOTg3ZWEwMWQtYjU4Ny00NzhkLWE0ODItNDVkN2U1NTMwZTE0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjA4VDEwNDAxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVjNDMzNDkzZDE4NjBjN2JkM2Y0MWUwN2E3ZTg2NWVmMWQ2NmNmZDVhOTA2Y2I0YTM4NzZmYmVmY2QwNmY1NmMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Es78lqgShf68ZRpAUg-VEN1817SaEes8pirLEARBkmY)
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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc4NDM1MTAsIm5iZiI6MTcxNzg0MzIxMCwicGF0aCI6Ii8zMTI5NjE3Ny8yNzgyOTIwNjAtNjFkNDNhODUtNWZjOC00MjE2LTk1NDMtOGIxMDFiNDgzZjIwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjA4VDEwNDAxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYwNDcwM2NmY2M3YTE4OTkwODRmY2U3YWZhNTc3MjQ3N2NlNTEwNjlhMTUwNGY0YWVjMDRkY2Q3ZWU3ZGE0NDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.fzs8Co_ZzZnL7nCGKEWIDayYwqU7T-drvYVqp8aGmj8)
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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc4NDM1MTAsIm5iZiI6MTcxNzg0MzIxMCwicGF0aCI6Ii8zMTI5NjE3Ny8yNzgyOTMzNzItYjY5NzczODEtNTQ4OS00YmY0LTk2NjAtMzk5MmZhOWQxY2RjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjA4VDEwNDAxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZjMWIxNTQ1YjhjZGE2YzA1YWZhN2VmOWE4OWYyNjBlYWVkMzc3NmJlOGZkMzQxYjQ0NjUzYzNiNjAwNGVmOGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.H2sJHy_DSvz2-9OxtBOYKULfLY6mbIW8QCAOV9v6ByY)
- 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