ops-py-message-handler
Description
Posts a payload / message to an url (webhook).
Installation
pip install ops-py-message-handler
Usage
Slack Workflow
Note: In the example code below a Slack Automation Workflow has already been built. The message part of the Slack Workflow has been defined to receive a Title and a Text variable.
Export your slack webhook:
export WEBHOOK="12345blablabla...."
Example code:
#!/usr/bin/env python
import os
from message_handler import message_handler as mh
WEBHOOK = os.getenv("WEBHOOK")
heading = "This is the heading"
message = "This is the message"
handler = mh.MessageHandler(WEBHOOK)
handler.build_payload(Title=heading, Text=message)
handler.post_payload()
response_code = handler.get_response_code()
print(response_code)
Slack App
Export your slack webhook:
export WEBHOOK="12345blablabla...."
Example code:
#!/usr/bin/env python
import os
from message_handler import message_handler as mh
WEBHOOK = os.getenv("WEBHOOK")
heading = "This is the heading"
message = "This is the message"
payload = {"text": f"*{heading}*\n```{message}```"}
handler = mh.MessageHandler(WEBHOOK)
handler.set_payload(payload)
handler.post_payload()
response_code = handler.get_response_code()
print(response_code)
MS Teams
Export your MS Teams webhook:
export WEBHOOK="12345blablabla...."
Example code:
#!/usr/bin/env python
import os
from message_handler import message_handler as mh
WEBHOOK = os.getenv("WEBHOOK")
payload = {
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "-",
"sections": [
{
"activityTitle": "Super Secret Key Vault",
"activitySubtitle": "",
"activityImage": "",
"facts": [],
"markdown": True
},
{
"startGroup": True,
"text": """<table bordercolor='black' border='2'>
<thead>
<tr style='background-color : Teal; color: White'>
<th>Secret Name</th>
<th>Last Updated</th>
<th>Expiration</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>SuperSecret</td>
<td>2023-10-31</td>
<td>2024-06-25</td>
<td>Will expire in 201 days. Updated 37 days ago.</td>
</tr>
</tbody>
</table>"""
}
]
}
handler = mh.MessageHandler(WEBHOOK)
handler.set_payload(payload)
handler.post_payload()
response_code = handler.get_response_code()
print(response_code)
Metadata
Release files for ops-py-message-handler 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ops_py_message_handler-1.0.7.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ops_py_message_handler-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / ops_py_message_handler-1.0.7.tar.gz
| Download URL | ops_py_message_handler-1.0.7.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d368e31a5cfa179b85b24c98820bd7156f0f050393a7f9e4f08f7afdc941b5aa
|
|
BLAKE2b-256 checksum How to use checksums |
eb7823e43869b585a7cc76afb627f42a4f744bbe8cdf89c7b71dc24a6339afeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2024.
Transparency logRelease files / ops_py_message_handler-1.0.7-py3-none-any.whl
| Download URL | ops_py_message_handler-1.0.7-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65fab46592ae02cf6822c699612c0a624575df49358e70712c4664d41a1e072b
|
|
BLAKE2b-256 checksum How to use checksums |
841485a056fd058e19ba95e44225b79f85151b6c7d08cad33edd42da1bf910e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2024.
Transparency log