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.
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'
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'
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.
- 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