-
-
Save vedraiyani/06c463bd6b215282be47e63d05d6803b to your computer and use it in GitHub Desktop.
Slack notification from python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
import json | |
SLACK_WEBHOOK= os.environ.get("SLACK_WEBHOOK") | |
def send_message(messages, channel="abhishek", username="beast"): | |
""" | |
:param messages: list of texts | |
:param channel: name of slack channel | |
:param username: username of the bot | |
""" | |
data = { | |
"username": username, | |
"channel": channel | |
} | |
data['text'] = '\n'.join(messages) | |
requests.post(SLACK_WEBHOOK, json.dumps(data)) | |
def send_dict(dictionary, channel="abhishek", username="beast"): | |
""" | |
:param dictionary: a dictionary (key, value) | |
:param channel: name of slack channel | |
:param username: username of the bot | |
""" | |
data = { | |
"username": username, | |
"channel": channel | |
} | |
values = [] | |
for k, v in dictionary.items(): | |
values.append(str(k) + ": " + str(v)) | |
data["text"] = "\n".join(values) | |
requests.post(SLACK_WEBHOOK, json.dumps(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment