Slack_ChatPostMessage - HomeMadePy/messages GitHub Wiki

The slack module provides an easy and intuitive interface to construct and send slack messages via the chat.PostMessage API.

SlackPost API

SlackPost(**from_**=None, auth=None, channel=None, body='', attachments=None, params=None, verbose=False)

  • from_: (str) [optional] The name/username/nickname the message will originate from, i.e. 'The Boss'
  • auth: (str) authorization token with the required scopes. May use environment variables to pull auth credentials or whatever means you feel necessary.
  • channel: (str) channel name to post the message to, i.e. "#general", "general", or in encoded format, like "C7ABC123".
  • body: (str) [optional] The body text of the message to send. Use body text from a file by setting body=file.read().
  • attachments: (str or list) [optional] a url, or list of urls who's content you wish to attach in the message, such as a url for a picture.
  • params: (dict) [optional] additional attributes to add to each attachment, i.e. author_name, title, text, etc., see API for information on which attributes are possible.
  • verbose: (bool) [optional] print verbose output.

Usage

After instantiating a SlackPost object, using the API above, the following method can be used to send the message:

  • send(): sends the message synchronously

Example

Script/REPL

>>> from messages import SlackPost
>>> s = SlackPost(
                from_='Your Robot!',
                auth='1234abcd',
                channel='general', 
                body='Buy more Bitcoin!', 
                attachments='https://imgs.xkcd.com/comics/python.png', 
        )
>>> s.send()         
Message sent...

SlackPost Service

In order to use this service, you must be a member of a Slack Team and have an authorization token with the required scopes. See the Slack API.