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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bca3723abd6a946ce12753b6ef519f73fdc5c794218c1ca11f18f8127dd83dc |
|
MD5 | a3841ee0bd90aea3dd7812c0929b4363 |
|
BLAKE2b-256 | 2dc62d469587b76a80fd4c38958a654a990f3810904aa3f7cecbb94c65b50f00 |
Close
Hashes for ops_py_message_handler-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 875fcccadc6041aabe1d88601a2d29d9e7b6437e269abb19b4a11e689a0b1e59 |
|
MD5 | 9d7773f92a94f2dd2bed205fe63ce8bd |
|
BLAKE2b-256 | d9fc65f38a1b6d7c490005f8b331c755d3f39f6e8208aba27ff920c02082d567 |