Send notifications to slack channel with supporting attachments and fields
Project description
Slack notifications
Simple usage
import os
from slack_notifications import send_notify
os.environ['SLACK_ACCESS_TOKEN'] = 'xxx'
send_notify('channel-name', username='Bot', text='@channel This is test message')
Use attachments
import os
from slack_notifications import send_notify, Attachment
os.environ['SLACK_ACCESS_TOKEN'] = 'xxx'
attachment = Attachment(
title='Attachment title',
pretext='Attachment pretext',
text='Attachment text',
footer='Attachment footer',
color='green',
)
send_notify('channel-name', username='Bot', text='@channel This is test message', attachments=[attachment])
Attachment fields
import os
from slack_notifications import send_notify, Attachment, AttachmentField
os.environ['SLACK_ACCESS_TOKEN'] = 'xxx'
field = AttachmentField(
title='Field title',
value='Field value',
)
attachment = Attachment(
title='Attachment title',
pretext='Attachment pretext',
text='Attachment text',
footer='Attachment footer',
fields=[field],
color='green',
)
send_notify('channel-name', username='Bot', text='@channel This is test message', attachments=[attachment])
Init attachment color
from slack_notifications import init_color
init_color('green', '#008000')
Call slack resource
import os
from slack_notifications import call_resource, Resource
os.environ['SLACK_ACCESS_TOKEN'] = 'xxx'
response = call_resource(Resource('users.info', 'GET'), params={'user': 'W1234567890'})
Resource iterator
import os
from slack_notifications import resource_iterator, Resource
os.environ['SLACK_ACCESS_TOKEN'] = 'xxx'
for user in resource_iterator(Resource('users.list', 'GET'), 'members'):
pass
Raise exception if error was given
import os
from slack_notifications import send_notify
os.environ['SLACK_ACCESS_TOKEN'] = 'xxx'
send_notify('channel-name', username='Bot', text='@channel This is test message', raise_exc=True)
Objects
AttachmentField
- title=None
- value=None
- short=False
Attachment
- image_url=None,
- thumb_url=None,
- author_name=None,
- author_link=None,
- author_icon=None,
- title=None,
- title_link=None,
- text=None,
- pretext=None,
- footer=None,
- footer_icon=None,
- timestamp=None,
- fields: List[AttachmentField] = None,
- color=None
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
Close
Hashes for slack-notifications-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5cf1fb9a7b1e1f45e552fe8ea8aecf0a1ded03236a33552abba5661d15dadc8 |
|
MD5 | 824a97f2456f1d68f83a17eb932ed38d |
|
BLAKE2b-256 | fbf3c7a247a503237c44adec96a5a616446410fdee59a7af070dcc0f358e46d8 |