-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandupbot.py
More file actions
38 lines (35 loc) · 1.48 KB
/
standupbot.py
File metadata and controls
38 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Make sure to replace 'YOUR_SLACK_TOKEN' with your actual Slack bot token.
This example uses Flask as a simple web server to handle incoming events from Slack. When the bot is mentioned in a channel, it sends a stand-up message to the user who mentioned the bot.
Remember to set up a Slack app, install it in your workspace, and obtain a bot token to use in the script. Adjust the code as needed based on your specific requirements and environment.
"""
import os
from slack import WebClient
from slack.errors import SlackApiError
from flask import Flask, request
app = Flask(__name__)
slack_token = 'YOUR_SLACK_TOKEN'
client = WebClient(token=slack_token)
def send_standup_message(channel, user):
standup_message = f"Hey <@{user}>, it's time for your stand-up! What did you accomplish yesterday? What are you planning to do today? Any blockers?"
try:
response = client.chat_postMessage(
channel=channel,
text=standup_message
)
print(response)
except SlackApiError as e:
print(f"Error sending stand-up message: {e.response['error']}")
@app.route('/standup', methods=['POST'])
def standup():
data = request.get_json()
if data['type'] == 'url_verification':
return data['challenge']
event = data['event']
if event['type'] == 'app_mention':
channel = event['channel']
user = event['user']
send_standup_message(channel, user)
return '', 200
if __name__ == '__main__':
app.run(port=3000)