A simple Slack bot for sending messages to channels and users
Project description
Slack DM Bot
A simple Python bot for sending direct messages to users on Slack.
Installation
- Install the required package:
pip install sims-slack-bot
Configuration
- Load the config file I'll send to y'all through slack. That config file contains the bot token and also the users ID so you can be found by the bot. The file format is as follows (JSON):
{
"slack_token": "xoxb-your-bot-token",
"users": {
"username1": "U12345678",
"username2": "U87654321"
}
}
Usage
from sims_slack_bot import EnhancedSlackBot
# Initialize the bot with your config file
bot = EnhancedSlackBot('config.json')
# Send a DM using username from config
bot.send_dm(
user_name="username1",
message="Hello! This is a test message",
emoji=":robot_face:" # Optional, defaults to :robot_face:
)
send_dm() Method Details
The send_dm() method allows you to send direct messages to Slack users in two ways:
Parameters
user_name(str): The username as defined in your config filemessage(str): The message content to sendemoji(str, optional): Custom emoji to appear before the message. Defaults to ":robot_face:"email(str, optional): User's Slack email address (alternative to username)
Features
- Messages are automatically formatted with timestamp and emoji
- Can identify users either by configured username or email address
- Provides error handling for invalid users or failed message delivery
- Prints confirmation when message is successfully sent
Example Output Format
Your message will be formatted as:
🤖 *Bot Message* (2024-01-14 15:30:45)
Your message text here
Error Handling
The method will raise a ValueError if:
- The specified username is not found in the config file
- The provided email doesn't correspond to a valid Slack user
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sims_slack_bot-0.1.0.tar.gz
(4.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sims_slack_bot-0.1.0.tar.gz.
File metadata
- Download URL: sims_slack_bot-0.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.6 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f8dc5ee3b5b1e1f0066130904b2dbcdc0150012296e574e7509e6ecaca5d100
|
|
| MD5 |
9c3a623e404989a992570ffdfb8c1473
|
|
| BLAKE2b-256 |
2a9da19e841fb2469d9fb1ba44bf81937b082d4cff04aba8bf5d3a343ce5971e
|
File details
Details for the file sims_slack_bot-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sims_slack_bot-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.6 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87a5a3e524e30ca652e7bbad68f821b98fd63dd5d3e54d59e459e5256025e780
|
|
| MD5 |
fba77b30df6d15dd7f367ddac1ac135d
|
|
| BLAKE2b-256 |
862d69237bd86c1e5bd7b5430db75bdea93dfbf6f4c78acfb56daea48cffabfc
|