Skip to content

huit/pyslack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyslack

A package to facilitate the use of a slack webhook for notifications.

Slack setup

Setup of a webhook in Slack is required. See https://api.slack.com/messaging/webhooks

Installation and Usage

- requires python >=3.7

pip install https://github.com/huit/pyslack/archive/v1.0.4.tar.gz

from pyslack.notify import NotificationService 

ns = NotificationService(webhook="<unique_id_for_slack_webhook>", username="<notification_username>", icon_emoji="<emoji>")

ns.success("SUCCESS TITLE") # only title required for success message
ns.info(title="INFO TITLE", message="informational message")
ns.warning(title="WARNING TITLE", message="warning message")
ns.error(title="ERROR TITLE", message="error message", link="https://www.example.com", link_title="Example.com")

Instantiation Notes

  1. <unique_id_for_slack_webhook> must be supplied by slack, and will be appended to "https://hooks.slack.com/services/"
  2. <notification_username> can be any string, not necessarily an existing slack user
  3. must be a valid slack emoji name - do not include any ':' as it will automatically be wrapped "::" NOTE: 'icon_emoji' has been deprecated; in the shift to new slack applications it is configured in the app

Parameters

  1. title -> REQUIRED
  2. message -> REQUIRED ( defaults to 'Success!' for .success() )
  3. link -> OPTIONAL ( must be a fully formed URL, e.g., https://www.example.com )
  4. link_title -> OPTIONAL ( if link parameter is supplied but not link_title, link_title defaults to 'link' )

Examples

pyslack_examples