Last active
January 17, 2022 00:48
-
-
Save qkdxorjs1002/4b05783527b30f46587b3e71c1e06557 to your computer and use it in GitHub Desktop.
Python Slack Message Push Bot
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 requests | |
class SlackPushBot: | |
def __init__(self, oauthToken, channelId): | |
# API Base URL | |
self.setBaseUrl("https://slack.com/api") | |
# OAuth Token | |
self.setOAuthToken(oauthToken) | |
# Notice Channel ID | |
self.setChannel(channelId) | |
def setBaseUrl(self, url): | |
self.baseUrl = url | |
def setOAuthToken(self, token): | |
self.oauthToken = token | |
def setChannel(self, channel): | |
self.channelId = channel | |
## /chat.postMessage | |
def postMessage(self, message, ts=""): | |
response = requests.post( | |
url = self.baseUrl + "/chat.postMessage", | |
headers = { | |
"Content-Type": "application/json;charset=utf-8", | |
"Authorization": "Bearer " + self.oauthToken | |
}, | |
json = { | |
"channel": self.channelId, | |
"text": message, | |
"thread_ts": ts | |
} | |
) | |
return response.json() |
Author
qkdxorjs1002
commented
Jan 10, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment