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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ops_py_message_handler-1.0.7.tar.gz.
File metadata
- Download URL: ops_py_message_handler-1.0.7.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d368e31a5cfa179b85b24c98820bd7156f0f050393a7f9e4f08f7afdc941b5aa
|
|
| MD5 |
cc479bc335b38ded88aa1b9e8061ed75
|
|
| BLAKE2b-256 |
eb7823e43869b585a7cc76afb627f42a4f744bbe8cdf89c7b71dc24a6339afeb
|
Provenance
The following attestation bundles were made for ops_py_message_handler-1.0.7.tar.gz:
Publisher:
build_pypi.yml on equinor/ops-py-message-handler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ops_py_message_handler-1.0.7.tar.gz -
Subject digest:
d368e31a5cfa179b85b24c98820bd7156f0f050393a7f9e4f08f7afdc941b5aa - Sigstore transparency entry: 149464841
- Sigstore integration time:
-
Permalink:
equinor/ops-py-message-handler@f99a852d9b766bd31e382c39989e854c5069a77e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/equinor
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_pypi.yml@f99a852d9b766bd31e382c39989e854c5069a77e -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file ops_py_message_handler-1.0.7-py3-none-any.whl.
File metadata
- Download URL: ops_py_message_handler-1.0.7-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65fab46592ae02cf6822c699612c0a624575df49358e70712c4664d41a1e072b
|
|
| MD5 |
cdcbea1dff3ceb095f59adaf03f61ccf
|
|
| BLAKE2b-256 |
841485a056fd058e19ba95e44225b79f85151b6c7d08cad33edd42da1bf910e0
|
Provenance
The following attestation bundles were made for ops_py_message_handler-1.0.7-py3-none-any.whl:
Publisher:
build_pypi.yml on equinor/ops-py-message-handler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ops_py_message_handler-1.0.7-py3-none-any.whl -
Subject digest:
65fab46592ae02cf6822c699612c0a624575df49358e70712c4664d41a1e072b - Sigstore transparency entry: 149464843
- Sigstore integration time:
-
Permalink:
equinor/ops-py-message-handler@f99a852d9b766bd31e382c39989e854c5069a77e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/equinor
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_pypi.yml@f99a852d9b766bd31e382c39989e854c5069a77e -
Trigger Event:
pull_request
-
Statement type: