Post a payload to specfied url
Project description
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)
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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdb1ddff901f831bc228444c693287225a7145c9d3c5c9f83f536f97105775aa |
|
MD5 | f4b14d41614630687f32cd1d9881aa82 |
|
BLAKE2b-256 | 8c6aa284b0e3c91b0d1a19cb316215cad4db019f991d20e2c0bd8decc8d65b3e |
Close
Hashes for ops_py_message_handler-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8503d1f56c52a531173989a9b3f331914b15e7a50b088c584134fde0b4e66741 |
|
MD5 | ff037e65dcf311367a21e48c8cc6ffa4 |
|
BLAKE2b-256 | b545f7c938ad36d7552beadeab039dfe8b01e8c8242ba63e42a5e8088d8a4794 |