alert-msgs


Namealert-msgs JSON
Version 0.7.2 PyPI version JSON
download
home_pageNone
SummaryEasily construct and send formatted emails and Slack alerts.
upload_time2024-10-14 16:29:00
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT
keywords alert message notification slack email
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Easily construct and send formatted emails and Slack alerts.

### Install
```bash
pip install alert_msgs
```

If using Slack as an alert destination, you will need to set up a [Slack App](https://api.slack.com/apps?new_app=1) and get a bot token configured with OAuth permissions.
1. Go to [Slack Apps](https://api.slack.com/apps?new_app=1). Click **Create New App** -> **From Scratch** (give it a name, select your workspace)
2. Navigate to the **OAuth & Permissions** on the left sidebar and scroll down to the **Bot Token Scopes** section. Add `chat:write` and `file:write` OAuth scopes.
3. Scroll up to the top of the **OAuth & Permissions** page and click **Install App to Workspace**.
4. Copy the **Bot User OAuth Token** from the **OAuth & Permissions** page. This is the value that should be used for the `bot_token` parameter of [Slack](./alert_msgs/config.py#L26) config.
5. In Slack, go to your channel and click the down arrow next to your channel name at the top. Click **Integrations** -> **Add apps** -> select the app you just made.

### Usage
[send_alert](./alert_msgs/alerts.py#L35) is the high-level/easiest way to send alerts.    
Alerts are composed of one or more messages, where each message is composed of one or more [components](./alert_msgs/components.py).   
Alerts can be sent to one or more Slack and/or Email destinations. See [destinations](./alert_msgs/destinations.py) for configuration.   


### Examples

```python
from alert_msgs import EmailAddrs, SlackChannel, ContentType, FontSize, Map, Text, Table, send_alert, send_slack_message, send_email
from uuid import uuid4
import random

components = [
    Text(
        "Important things have happened.",
        size=FontSize.LARGE,
        color=ContentType.IMPORTANT,
    ),
    Map({"Field1": "Value1", "Field2": "Value2", "Field3": "Value3"}),
    Table(
        rows=[
            {
                "Process": "thing-1",
                "Status": 0,
                "Finished": True,
            },
            {
                "Process": "thing-2",
                "Status": 1,
                "Finished": False,
            }
        ],
        caption="Process Status",
    ),
]

send_to = [
    EmailAddrs(sender_addr="me@gmail.com", password="myemailpass", receiver_addr=["someone@gmail.com","someone2@gmail.com"]), 
    SlackChannel(bot_token="xoxb-34248928439763-6634233945735-KbePKXfstIRv6YN2tW5UF8tS", channel="my-channel")
]
send_alert(components, subject="Test Alert",  send_to=send_to)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "alert-msgs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "alert, message, notification, slack, email",
    "author": null,
    "author_email": "Dan Kelleher <kelleherjdan@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "## Easily construct and send formatted emails and Slack alerts.\n\n### Install\n```bash\npip install alert_msgs\n```\n\nIf using Slack as an alert destination, you will need to set up a [Slack App](https://api.slack.com/apps?new_app=1) and get a bot token configured with OAuth permissions.\n1. Go to [Slack Apps](https://api.slack.com/apps?new_app=1). Click **Create New App** -> **From Scratch** (give it a name, select your workspace)\n2. Navigate to the **OAuth & Permissions** on the left sidebar and scroll down to the **Bot Token Scopes** section. Add `chat:write` and `file:write` OAuth scopes.\n3. Scroll up to the top of the **OAuth & Permissions** page and click **Install App to Workspace**.\n4. Copy the **Bot User OAuth Token** from the **OAuth & Permissions** page. This is the value that should be used for the `bot_token` parameter of [Slack](./alert_msgs/config.py#L26) config.\n5. In Slack, go to your channel and click the down arrow next to your channel name at the top. Click **Integrations** -> **Add apps** -> select the app you just made.\n\n### Usage\n[send_alert](./alert_msgs/alerts.py#L35) is the high-level/easiest way to send alerts.    \nAlerts are composed of one or more messages, where each message is composed of one or more [components](./alert_msgs/components.py).   \nAlerts can be sent to one or more Slack and/or Email destinations. See [destinations](./alert_msgs/destinations.py) for configuration.   \n\n\n### Examples\n\n```python\nfrom alert_msgs import EmailAddrs, SlackChannel, ContentType, FontSize, Map, Text, Table, send_alert, send_slack_message, send_email\nfrom uuid import uuid4\nimport random\n\ncomponents = [\n    Text(\n        \"Important things have happened.\",\n        size=FontSize.LARGE,\n        color=ContentType.IMPORTANT,\n    ),\n    Map({\"Field1\": \"Value1\", \"Field2\": \"Value2\", \"Field3\": \"Value3\"}),\n    Table(\n        rows=[\n            {\n                \"Process\": \"thing-1\",\n                \"Status\": 0,\n                \"Finished\": True,\n            },\n            {\n                \"Process\": \"thing-2\",\n                \"Status\": 1,\n                \"Finished\": False,\n            }\n        ],\n        caption=\"Process Status\",\n    ),\n]\n\nsend_to = [\n    EmailAddrs(sender_addr=\"me@gmail.com\", password=\"myemailpass\", receiver_addr=[\"someone@gmail.com\",\"someone2@gmail.com\"]), \n    SlackChannel(bot_token=\"xoxb-34248928439763-6634233945735-KbePKXfstIRv6YN2tW5UF8tS\", channel=\"my-channel\")\n]\nsend_alert(components, subject=\"Test Alert\",  send_to=send_to)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Easily construct and send formatted emails and Slack alerts.",
    "version": "0.7.2",
    "project_urls": null,
    "split_keywords": [
        "alert",
        " message",
        " notification",
        " slack",
        " email"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4f0f07b9f116111462f9b30d2fd8f4a43a776eedeaad33599a35bc414e6b291",
                "md5": "8aa7b708d86dbae3df2343426618db3e",
                "sha256": "1df435605b92fa7feb675b8238be809a89bea8f005bf83bdd53da38aabf043ab"
            },
            "downloads": -1,
            "filename": "alert_msgs-0.7.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8aa7b708d86dbae3df2343426618db3e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 13377,
            "upload_time": "2024-10-14T16:29:00",
            "upload_time_iso_8601": "2024-10-14T16:29:00.305610Z",
            "url": "https://files.pythonhosted.org/packages/c4/f0/f07b9f116111462f9b30d2fd8f4a43a776eedeaad33599a35bc414e6b291/alert_msgs-0.7.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-14 16:29:00",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "alert-msgs"
}
        
Elapsed time: 0.32552s