Python API and CLI for sending message in Slack
Project description
Python API and CLI for sending message in Slack
toslack is a Python package that helps you send messages, images or files to slack channels with simple settings. Command line tools are also provided to do the same thing.
Requirements
- Python Version: Ensure you are using Python 3.6 or higher.
- Dependencies:
slack_sdk
(version 3.31.0)dataclasses
(built-in for Python 3.6+)typing
(for type hinting)
Installation
pip install toslack
Sending a message to Slack
One of the most common use-cases is sending a message to Slack. If your app's bot user is not in a channel yet, invite the bot user before running the code snippet (or add chat:write.public
to Bot Token Scopes for posting in any public channels).
import os
from toslack import SlackMessage
from toslack import SlackClient
client = SlackClient(token=os.environ['SLACK_BOT_TOKEN'], channel=os.environ['TO_SLACK_CHANNEL'])
message = SlackMessage(client=client)
message.post(text="Hello world!")
Or posting your message by the command line.
python slack.py --token xxx --channel C123456 post $message
Uploading files to Slack
You can just include a path to the file directly in the API call and upload it that way.
import os
from toslack import SlackMessage
from toslack import SlackClient
client = SlackClient(token=os.environ['SLACK_BOT_TOKEN'], channel=os.environ['TO_SLACK_CHANNEL'])
message = SlackMessage(client=client)
message.upload(file_path="./tmp.txt")
Or upload by specifying the file path on the command line.
python slack.py --token xxx --channel C123456 upload $file_path
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
Built Distribution
File details
Details for the file toslack-0.1.0.tar.gz
.
File metadata
- Download URL: toslack-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4cbac632dae6eb3470c845a74338a284db78ec30a20e45f27a6b74dd55be167 |
|
MD5 | 0f93661d2bd5bdda586516eda8c69b95 |
|
BLAKE2b-256 | f9f0298da143cee39424aeb94c5241a3ed0a8ed369fb23e2dd295dbdb1c14f06 |
File details
Details for the file toslack-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: toslack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43a9a7b30e6ca3448c2afa00126311492bc06de67dd2524e31a77ca2967deb4d |
|
MD5 | 70b7cc869342fe293fc4f5a7c97539fe |
|
BLAKE2b-256 | 7b123b4eac584723c46d7fa8b8b1e3ad06c708e8e0ca1b0b4c3d01e3156aea5e |