slack-notifications


Nameslack-notifications JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/qa-team-tools/slack-notifications
SummarySend notifications to slack channel with supporting attachments and fields
upload_time2024-07-23 12:33:50
maintainerNone
docs_urlNone
authorMikhail Trifonov
requires_pythonNone
licenseNone
keywords slack notifications
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Slack notifications

## Installation

```bash
pip install slack-notifications
```


## Simple usage

```python
import os

import slack_notifications as slack


slack.ACCESS_TOKEN = 'xxx'


slack.send_notify('channel-name', username='Bot', text='@channel This is test message')
```

or

```python
import os

from slack_notifications import Slack


slack = Slack('<token>')
slack.send_notify('channel-name', username='Bot', text='@channel This is test message')
```

## Message

```python
import os

from slack_notifications import Slack, Attachment


slack = Slack('<token>')
message = slack.send_notify('channel-name', username='Bot', text='@channel This is test message')

message.text = 'This is test message'
message.update()

message.add_reaction('<name>')
message.remove_reaction('<name>')

message.upload_file('./test.yml', filetype='yaml')

message.attachments.append(
    Attachment(
        title='Attachment title',
        pretext='Attachment pretext',
        text='Attachment text',
        footer='Attachment footer',
        color='green',
    ),
)
message.update()
```

## Use attachments

```python
import os

import slack_notifications as slack


slack.ACCESS_TOKEN = 'xxx'


attachment = slack.Attachment(
    title='Attachment title',
    pretext='Attachment pretext',
    text='Attachment text',
    footer='Attachment footer',
    color='green',
)

slack.send_notify('channel-name', username='Bot', text='@channel This is test message', attachments=[attachment])
```

See program API


## Attachment fields

```python
import slack_notifications as slack


slack.ACCESS_TOKEN = 'xxx'


attachment = slack.Attachment(
    title='Attachment title',
    pretext='Attachment pretext',
    text='Attachment text',
    footer='Attachment footer',
    fields=[
        slack.Attachment.Field(
            title='Field title',
            value='Field value',
        ),
    ],
    color='green',
)

slack.send_notify('channel-name', username='Bot', text='@channel This is test message', attachments=[attachment])
```


## Simple Text Block

```python
import slack_notifications as slack


slack.ACCESS_TOKEN = 'xxx'


block = slack.SimpleTextBlock(
    'Text example',
    fields=[
        slack.SimpleTextBlock.Field(
            'Text field',
        ),
        slack.SimpleTextBlock.Field(
            'Text field',
            emoji=True,
        ),
    ],
)

slack.send_notify('channel-name', username='Bot', text='@channel This is test message', blocks=[block])
```

## Action Block

```python
import slack_notifications as slack


slack.ACCESS_TOKEN = 'xxx'


block = slack.ActionsBlock(
    elements=[
        slack.ButtonBlock(
            'Yes', 
            action_id='action1',
            value='some_data1',
            style='primary'
        ),
        slack.ButtonBlock(
            'No', 
            action_id='action2',
            value='some_data2',
            style='danger'
        ),
    ],
)

slack.send_notify('channel-name', username='Bot', text='@channel This is test message', blocks=[block])
```


## Use mrkdwn module

```python
import slack_notifications as slack


block = slack.SimpleTextBlock(
    'Text example',
    fields=[
        slack.SimpleTextBlock.Field(
            slack.mrkdwn.bold('Text field'),
        ),
        slack.SimpleTextBlock.Field(
            slack.mrkdwn.italic('Text field'),
            emoji=True,
        ),
    ],
)
```

## Mattermost interface

### Simple usage

```python
import os

import slack_notifications.mattermost as mattermost


mattermost.ACCESS_TOKEN = 'xxx'
mattermost.BASE_URL_ENV_NAME = 'http://your-mattermost-url.com/api/v4'
mattermost.TEAM_ID_ENV_NAME = 'xxx'

mattermost.send_notify('channel-name', username='Bot', text='@channel This is test message')
```

or

```python
import os

from slack_notifications.mattermost import Mattermost


mattermost = Mattermost('http://your-mattermost-url.com/api/v4',
                   token='<token>',
                   team_id='xxx')
mattermost.send_notify('channel-name', username='Bot', text='@channel This is test message')
```


### Use fields for Mattermost

```python
import slack_notifications.mattermost as mattermost
import slack_notifications as slack


mattermost.ACCESS_TOKEN = 'xxx'
mattermost.BASE_URL = 'http://your-mattermost-url.com/api/v4'
mattermost.TEAM_ID = 'xxx'


block = slack.SimpleTextBlock(
    'Text example',
    fields=[
        slack.SimpleTextBlock.Field(
            'Text field',
        ),
        slack.SimpleTextBlock.Field(
            'Text field',
            emoji=True,
        ),
    ],
)

mattermost.send_notify('channel-name', username='Bot', text='@channel This is test message', blocks=[block])
```


### Use mrkdwn module for Mattermost

```python
import slack_notifications as slack
from slack_notifications.mattermost import mrkdwn


block = slack.SimpleTextBlock(
    'Text example',
    fields=[
        slack.SimpleTextBlock.Field(
            mrkdwn.bold('Text field'),
        ),
        slack.SimpleTextBlock.Field(
            mrkdwn.italic('Text field'),
            emoji=True,
        ),
    ],
)
```
See program API

## Init color

```python
import slack_notifications as slack


slack.init_color('green', '#008000')
```


## Call slack resource

```python
import slack_notifications as slack


slack.ACCESS_TOKEN = 'xxx'


response = slack.call_resource(slack.Resource('users.info', 'GET'), params={'user': 'W1234567890'})
```


## Resource iterator

```python
import slack_notifications as slack


slack.ACCESS_TOKEN = 'xxx'


for user in slack.resource_iterator(slack.Resource('users.list', 'GET'), 'members'):
    pass
```


## Raise exception if error was given

```python
import slack_notifications as slack


slack.ACCESS_TOKEN = 'xxx'


slack.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

## upload_file

* channel
* file
* title: str = None,
* content: str = None,
* filename: str = None,
* thread_ts: str = None,
* filetype: str = 'text',
* raise_exc: bool = False

## 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


## ActionsBlock
* elements: List[ButtonBlock]

### ButtonBlock
* text: str
* action_id: str
* value: str
* style: str = None

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/qa-team-tools/slack-notifications",
    "name": "slack-notifications",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "slack notifications",
    "author": "Mikhail Trifonov",
    "author_email": "trifonov.net@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bd/98/d30d81755545505e90be96929ec83fdf85cb7ced527d3aad5e0f15b99be5/slack_notifications-1.0.1.tar.gz",
    "platform": null,
    "description": "# Slack notifications\n\n## Installation\n\n```bash\npip install slack-notifications\n```\n\n\n## Simple usage\n\n```python\nimport os\n\nimport slack_notifications as slack\n\n\nslack.ACCESS_TOKEN = 'xxx'\n\n\nslack.send_notify('channel-name', username='Bot', text='@channel This is test message')\n```\n\nor\n\n```python\nimport os\n\nfrom slack_notifications import Slack\n\n\nslack = Slack('<token>')\nslack.send_notify('channel-name', username='Bot', text='@channel This is test message')\n```\n\n## Message\n\n```python\nimport os\n\nfrom slack_notifications import Slack, Attachment\n\n\nslack = Slack('<token>')\nmessage = slack.send_notify('channel-name', username='Bot', text='@channel This is test message')\n\nmessage.text = 'This is test message'\nmessage.update()\n\nmessage.add_reaction('<name>')\nmessage.remove_reaction('<name>')\n\nmessage.upload_file('./test.yml', filetype='yaml')\n\nmessage.attachments.append(\n    Attachment(\n        title='Attachment title',\n        pretext='Attachment pretext',\n        text='Attachment text',\n        footer='Attachment footer',\n        color='green',\n    ),\n)\nmessage.update()\n```\n\n## Use attachments\n\n```python\nimport os\n\nimport slack_notifications as slack\n\n\nslack.ACCESS_TOKEN = 'xxx'\n\n\nattachment = slack.Attachment(\n    title='Attachment title',\n    pretext='Attachment pretext',\n    text='Attachment text',\n    footer='Attachment footer',\n    color='green',\n)\n\nslack.send_notify('channel-name', username='Bot', text='@channel This is test message', attachments=[attachment])\n```\n\nSee program API\n\n\n## Attachment fields\n\n```python\nimport slack_notifications as slack\n\n\nslack.ACCESS_TOKEN = 'xxx'\n\n\nattachment = slack.Attachment(\n    title='Attachment title',\n    pretext='Attachment pretext',\n    text='Attachment text',\n    footer='Attachment footer',\n    fields=[\n        slack.Attachment.Field(\n            title='Field title',\n            value='Field value',\n        ),\n    ],\n    color='green',\n)\n\nslack.send_notify('channel-name', username='Bot', text='@channel This is test message', attachments=[attachment])\n```\n\n\n## Simple Text Block\n\n```python\nimport slack_notifications as slack\n\n\nslack.ACCESS_TOKEN = 'xxx'\n\n\nblock = slack.SimpleTextBlock(\n    'Text example',\n    fields=[\n        slack.SimpleTextBlock.Field(\n            'Text field',\n        ),\n        slack.SimpleTextBlock.Field(\n            'Text field',\n            emoji=True,\n        ),\n    ],\n)\n\nslack.send_notify('channel-name', username='Bot', text='@channel This is test message', blocks=[block])\n```\n\n## Action Block\n\n```python\nimport slack_notifications as slack\n\n\nslack.ACCESS_TOKEN = 'xxx'\n\n\nblock = slack.ActionsBlock(\n    elements=[\n        slack.ButtonBlock(\n            'Yes', \n            action_id='action1',\n            value='some_data1',\n            style='primary'\n        ),\n        slack.ButtonBlock(\n            'No', \n            action_id='action2',\n            value='some_data2',\n            style='danger'\n        ),\n    ],\n)\n\nslack.send_notify('channel-name', username='Bot', text='@channel This is test message', blocks=[block])\n```\n\n\n## Use mrkdwn module\n\n```python\nimport slack_notifications as slack\n\n\nblock = slack.SimpleTextBlock(\n    'Text example',\n    fields=[\n        slack.SimpleTextBlock.Field(\n            slack.mrkdwn.bold('Text field'),\n        ),\n        slack.SimpleTextBlock.Field(\n            slack.mrkdwn.italic('Text field'),\n            emoji=True,\n        ),\n    ],\n)\n```\n\n## Mattermost interface\n\n### Simple usage\n\n```python\nimport os\n\nimport slack_notifications.mattermost as mattermost\n\n\nmattermost.ACCESS_TOKEN = 'xxx'\nmattermost.BASE_URL_ENV_NAME = 'http://your-mattermost-url.com/api/v4'\nmattermost.TEAM_ID_ENV_NAME = 'xxx'\n\nmattermost.send_notify('channel-name', username='Bot', text='@channel This is test message')\n```\n\nor\n\n```python\nimport os\n\nfrom slack_notifications.mattermost import Mattermost\n\n\nmattermost = Mattermost('http://your-mattermost-url.com/api/v4',\n                   token='<token>',\n                   team_id='xxx')\nmattermost.send_notify('channel-name', username='Bot', text='@channel This is test message')\n```\n\n\n### Use fields for Mattermost\n\n```python\nimport slack_notifications.mattermost as mattermost\nimport slack_notifications as slack\n\n\nmattermost.ACCESS_TOKEN = 'xxx'\nmattermost.BASE_URL = 'http://your-mattermost-url.com/api/v4'\nmattermost.TEAM_ID = 'xxx'\n\n\nblock = slack.SimpleTextBlock(\n    'Text example',\n    fields=[\n        slack.SimpleTextBlock.Field(\n            'Text field',\n        ),\n        slack.SimpleTextBlock.Field(\n            'Text field',\n            emoji=True,\n        ),\n    ],\n)\n\nmattermost.send_notify('channel-name', username='Bot', text='@channel This is test message', blocks=[block])\n```\n\n\n### Use mrkdwn module for Mattermost\n\n```python\nimport slack_notifications as slack\nfrom slack_notifications.mattermost import mrkdwn\n\n\nblock = slack.SimpleTextBlock(\n    'Text example',\n    fields=[\n        slack.SimpleTextBlock.Field(\n            mrkdwn.bold('Text field'),\n        ),\n        slack.SimpleTextBlock.Field(\n            mrkdwn.italic('Text field'),\n            emoji=True,\n        ),\n    ],\n)\n```\nSee program API\n\n## Init color\n\n```python\nimport slack_notifications as slack\n\n\nslack.init_color('green', '#008000')\n```\n\n\n## Call slack resource\n\n```python\nimport slack_notifications as slack\n\n\nslack.ACCESS_TOKEN = 'xxx'\n\n\nresponse = slack.call_resource(slack.Resource('users.info', 'GET'), params={'user': 'W1234567890'})\n```\n\n\n## Resource iterator\n\n```python\nimport slack_notifications as slack\n\n\nslack.ACCESS_TOKEN = 'xxx'\n\n\nfor user in slack.resource_iterator(slack.Resource('users.list', 'GET'), 'members'):\n    pass\n```\n\n\n## Raise exception if error was given\n\n```python\nimport slack_notifications as slack\n\n\nslack.ACCESS_TOKEN = 'xxx'\n\n\nslack.send_notify('channel-name', username='Bot', text='@channel This is test message', raise_exc=True)\n```\n\n\n# Program API\n\n## send_notify\n\n* channel\n* text: str = None\n* username: str = None\n* icon_url: str = None\n* icon_emoji: str = None\n* link_names: bool = True\n* raise_exc: bool = False\n* attachments: List[Attachment] = None\n* blocks: List[BaseBlock] = None\n\n## upload_file\n\n* channel\n* file\n* title: str = None,\n* content: str = None,\n* filename: str = None,\n* thread_ts: str = None,\n* filetype: str = 'text',\n* raise_exc: bool = False\n\n## call_resource\n\n* resource: Resource\n* raise_exc: bool = False\n* **kwargs (requests lib options)\n\n\n## resource_iterator\n\n* resource: Resource\n* from_key: str\n* cursor: str = None\n* raise_exc: bool = False\n* limit: int = DEFAULT_RECORDS_LIMIT\n\n\n## init_color\n\n* name: str\n* code: str\n\n\n## Attachment\n\n* image_url: str = None,\n* thumb_url: str = None,\n* author_name: str = None,\n* author_link: str = None,\n* author_icon: str = None,\n* title: str = None,\n* title_link: str = None,\n* text: str = None,\n* pretext: str = None,\n* footer: str = None,\n* footer_icon: str = None,\n* timestamp: str = None,\n* fields: List[Attachment.Field] = None,\n* color: str = None\n\n### Attachment.Field\n\n* title: str = None\n* value: str = None\n* short: bool = False\n\n\n## SimpleTextBlock\n\n* text: str\n* mrkdwn: bool = True\n* block_id: str = None\n* fields: List[SimpleTextBlock.Field] = None\n\n### SimpleTextBlock.Field\n\n* text: str\n* emoji: bool = False\n* mrkdwn: bool = True\n\n\n## DividerBlock\n\n* block_id: str = None\n\n\n## ImageBlock\n\n* image_url: str\n* title: str = None\n* alt_text: str = None\n* mrkdwn: bool = True\n* block_id: str = None\n\n\n## ContextBlock\n\n* elements: List[Union[ContextBlock.TextElement, ContextBlock.ImageElement]]\n* block_id: str = None\n\n### ContextBlock.TextElement\n\n* text: str\n* mrkdwn: bool = True\n\n### ContextBlock.ImageElement\n\n* image_url: str\n* alt_text: str = None\n\n\n## ActionsBlock\n* elements: List[ButtonBlock]\n\n### ButtonBlock\n* text: str\n* action_id: str\n* value: str\n* style: str = None\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Send notifications to slack channel with supporting attachments and fields",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/qa-team-tools/slack-notifications"
    },
    "split_keywords": [
        "slack",
        "notifications"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ac9b43a9a903d84db279b6b8de11152d973fbf14ef5b66e98ee32bbaf8527a9",
                "md5": "d4bda08544ddd4156291aab0a8886b72",
                "sha256": "9110b890c995a4902c8b2cbdb56a65036aa12ca4e9e567ae7ad4e7fc93dcfbd0"
            },
            "downloads": -1,
            "filename": "slack_notifications-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d4bda08544ddd4156291aab0a8886b72",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15698,
            "upload_time": "2024-07-23T12:33:49",
            "upload_time_iso_8601": "2024-07-23T12:33:49.153847Z",
            "url": "https://files.pythonhosted.org/packages/2a/c9/b43a9a903d84db279b6b8de11152d973fbf14ef5b66e98ee32bbaf8527a9/slack_notifications-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd98d30d81755545505e90be96929ec83fdf85cb7ced527d3aad5e0f15b99be5",
                "md5": "6164cf8603493a51b64291700c89997f",
                "sha256": "83840ff6ba6de22f54285c87213b779d7e1e81b220b1f36fd342d40100745bee"
            },
            "downloads": -1,
            "filename": "slack_notifications-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6164cf8603493a51b64291700c89997f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11960,
            "upload_time": "2024-07-23T12:33:50",
            "upload_time_iso_8601": "2024-07-23T12:33:50.542122Z",
            "url": "https://files.pythonhosted.org/packages/bd/98/d30d81755545505e90be96929ec83fdf85cb7ced527d3aad5e0f15b99be5/slack_notifications-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-23 12:33:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "qa-team-tools",
    "github_project": "slack-notifications",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "slack-notifications"
}
        
Elapsed time: 0.33615s