ask-for-help test
Browse files
app.py
CHANGED
@@ -41,12 +41,35 @@ async def on_message(message):
|
|
41 |
if message.author == bot.user:
|
42 |
return
|
43 |
|
|
|
44 |
content = message.content.lower()
|
45 |
for trigger, slack_mention in TRIGGERS.items():
|
46 |
if trigger in content:
|
47 |
await post_to_slack(message.author, message.content, message.channel.name, message.jump_url, slack_mention, trigger)
|
48 |
break
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
async def post_to_slack(author, content, channel, url, slack_mention, trigger):
|
51 |
try:
|
52 |
response = slack_client.chat_postMessage(
|
|
|
41 |
if message.author == bot.user:
|
42 |
return
|
43 |
|
44 |
+
# notification bot
|
45 |
content = message.content.lower()
|
46 |
for trigger, slack_mention in TRIGGERS.items():
|
47 |
if trigger in content:
|
48 |
await post_to_slack(message.author, message.content, message.channel.name, message.jump_url, slack_mention, trigger)
|
49 |
break
|
50 |
|
51 |
+
# ask-for-help
|
52 |
+
if message.channel.id == 1019883044724822016:
|
53 |
+
title = message.embeds[0].title if message.embeds else "No Title"
|
54 |
+
content = message.content
|
55 |
+
|
56 |
+
try:
|
57 |
+
# title
|
58 |
+
response = slack_client.chat_postMessage(
|
59 |
+
channel=SLACK_CHANNEL,
|
60 |
+
text=f"New post in {message.channel.name} by {message.author}:\n*{title}*"
|
61 |
+
)
|
62 |
+
# reply in thread
|
63 |
+
thread_ts = response['ts']
|
64 |
+
slack_client.chat_postMessage(
|
65 |
+
channel=SLACK_CHANNEL,
|
66 |
+
text=content,
|
67 |
+
thread_ts=thread_ts
|
68 |
+
)
|
69 |
+
except SlackApiError as e:
|
70 |
+
print(f"Error posting to Slack: {e.response['error']}")
|
71 |
+
|
72 |
+
|
73 |
async def post_to_slack(author, content, channel, url, slack_mention, trigger):
|
74 |
try:
|
75 |
response = slack_client.chat_postMessage(
|