Send notifications to slack channel with supporting attachments and fields
Project description
Slack notifications
Installation
pip install 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])
See program API
Attachment fields
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',
fields=[
Attachment.Field(
title='Field title',
value='Field value',
),
],
color='green',
)
send_notify('channel-name', username='Bot', text='@channel This is test message', attachments=[attachment])
Simple Text Block
import os
from slack_notifications import send_notify, SimpleTextBlock
os.environ['SLACK_ACCESS_TOKEN'] = 'xxx'
block = SimpleTextBlock(
'Text example',
fields=[
SimpleTextBlock.Field(
'Text field',
),
SimpleTextBlock.Field(
'Text field',
emoji=True,
),
],
)
send_notify('channel-name', username='Bot', text='@channel This is test message', blocks=[block])
See program API
Init 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)
Program API
send_notify
- channel
- text: str = None
- username: str = None
- icon_url: str = None
- icon_emoji: str = None
- link_names: bool = True
- raise_exc: bool = False
- attachments: List[Attachment] = None
- blocks: List[BaseBlock] = None
call_resource
- resource: Resource
- raise_exc: bool = False
- **kwargs (requests lib options)
resource_iterator
- resource: Resource
- from_key: str
- cursor: str = None
- raise_exc: bool = False
- limit: int = DEFAULT_RECORDS_LIMIT
init_color
- name: str
- code: str
Attachment
- image_url: str = None,
- thumb_url: str = None,
- author_name: str = None,
- author_link: str = None,
- author_icon: str = None,
- title: str = None,
- title_link: str = None,
- text: str = None,
- pretext: str = None,
- footer: str = None,
- footer_icon: str = None,
- timestamp: str = None,
- fields: List[Attachment.Field] = None,
- color: str = None
Attachment.Field
- title: str = None
- value: str = None
- short: bool = False
SimpleTextBlock
- text: str
- mrkdwn: bool = True
- block_id: str = None
- fields: List[SimpleTextBlock.Field] = None
SimpleTextBlock.Field
- text: str
- emoji: bool = False
- mrkdwn: bool = True
DividerBlock
- block_id: str = None
ImageBlock
- image_url: str
- title: str = None
- alt_text: str = None
- mrkdwn: bool = True
- block_id: str = None
ContextBlock
- elements: List[Union[ContextBlock.TextElement, ContextBlock.ImageElement]]
- block_id: str = None
ContextBlock.TextElement
- text: str
- mrkdwn: bool = True
ContextBlock.ImageElement
- image_url: str
- alt_text: str = 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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b0cbd135871eef2e4f995db745638ee297ec6516c4fa8c9f67de142ac4b48e7 |
|
MD5 | 73fa41e48a0b67221158d0c48406bc7b |
|
BLAKE2b-256 | a89297613c8664f5530f85dba420d0a867f147ced59970d2f923338190a140f9 |