Slack_IncomingWebhook - HomeMadePy/messages GitHub Wiki
The slack module provides an easy and intuitive interface to construct and send slack messages via the Incoming Webhooks API.
SlackWebhook API
SlackWebhook(**from_**=None, auth=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) webhook url for installed slack app. See API documentation. May use environment variables to pull auth credentials or whatever means you feel necessary.
- 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 SlackWebhook 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 SlackWebhook
>>> s = SlackWebhook(
from_='The Boss!',
auth='https://hooks.slack.com/services/Q7HWV7/EXAMPLE/JKLJDF89',
body='TestMessage',
attachments='https://imgs.xkcd.com/comics/python.png',
)
>>> s.send()
Message sent...
SlackWebhook Service
In order to use this service, you must be a member of a Slack Team and have the ability to install an app in the team. See the Slack API.