Post a payload to specfied url
Project description
ops-py-message-handler
Description
Post a message to a url (webhook).
Installation
pip install ops-py-message-handler
Usage
Slack
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:
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)
MS Teams
Export your MS Teams webhook:
export WEBHOOK="12345blablabla...."
Example code:
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)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for ops-py-message-handler-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 051e7d034b213f88bbbd5ea4dccfc380631b68f61e1435ce5f62d648fb552c9a |
|
MD5 | 2493a001eb429241dc3bbb25d162e9bd |
|
BLAKE2b-256 | 98b77e5f480ff2cdb0d24facd307d963fca7aef78cac91089c9ac3b7970983fd |
Close
Hashes for ops_py_message_handler-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26586b8a79642c15fe05546d9d850951c29283f1974d95dcd35e4757ab63f6f5 |
|
MD5 | 0991d7d1b75febb66e48b5787c14147c |
|
BLAKE2b-256 | 6a5a1a39afe4bf40ff7d94b390fa7944eefd0e96fbdef782a7ef9fd9e82fe630 |