Skip to content

HowieMen/toslack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python API and CLI for sending message in Slack

PyPI - Version slack-to Versions Python Versions

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

About

Python API and CLI for sending message in Slack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages