47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import slack
|
|
from flask import Flask
|
|
from slackeventsapi import SlackEventAdapter
|
|
from pprint import pprint
|
|
|
|
with open(".slacksecret") as f:
|
|
SLACK_TOKEN = f.read().strip()
|
|
|
|
with open(".slacksigningsecret") as f:
|
|
SIGNING_SECRET = f.read().strip()
|
|
|
|
app = Flask(__name__)
|
|
slack_event_adapter = SlackEventAdapter(SIGNING_SECRET, "/slack/events", app)
|
|
|
|
client = slack.WebClient(token=SLACK_TOKEN)
|
|
|
|
|
|
@slack_event_adapter.on("message")
|
|
def message(payload):
|
|
pprint(payload)
|
|
event = payload.get("event", {})
|
|
channel_id = event.get("channel")
|
|
user_id = event.get("uesr")
|
|
text = event.get("text")
|
|
|
|
if text == "cn":
|
|
client.chat_postMessage(
|
|
channel=channel_id,
|
|
text="Don't get me started on them! :coff:",
|
|
)
|
|
|
|
# if text == "image":
|
|
# try:
|
|
# response = client.files_upload(
|
|
# file="./images/lmao.png",
|
|
# initial_comment="I can read the chat messages",
|
|
# channels=channel_id,
|
|
# )
|
|
# except slack.SlackApiError as e:
|
|
# assert e.response["ok"] is False
|
|
# assert e.response["error"]
|
|
# print(f"Got an error: {e.response['error']}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=True, host="0.0.0.0")
|