forked from vishwa35/slackbot-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
48 lines (36 loc) · 1.29 KB
/
server.py
File metadata and controls
48 lines (36 loc) · 1.29 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
39
40
41
42
43
44
45
46
47
48
from flask import Flask, request, make_response, Response
import json
from tokens import SLACK_BOT_TOKEN, SLACK_VERIFICATION_TOKEN
from slackclient import SlackClient
from slashCommand import *
slack_client = SlackClient(SLACK_BOT_TOKEN)
app = Flask(__name__)
commander = Slash("Hey there! It works.")
#TODO: Add checks for all responses from slack api calls
def verify_slack_token(request_token):
if SLACK_VERIFICATION_TOKEN != request_token:
print("Error: invalid verification token!")
print("Received {} but was expecting {}".format(request_token, SLACK_VERIFICATION_TOKEN))
return make_response("Request contains invalid Slack verification token", 403)
@app.route("/slack/test", methods=["POST"])
def command():
info = request.form
# # get uid of the user
# im_id = slack_client.api_call(
# "im.open",
# user=info["user_id"]
# )["channel"]["id"]
# # send user a response via DM
# ownerMsg = slack_client.api_call(
# "chat.postMessage",
# channel=im_id,
# text=commander.getMessage()
# send channel a response
channelMsg = slack_client.api_call(
"chat.postMessage",
channel="#" + info["channel_name"],
text=commander.getMessage()
return make_response("", 200)
# Start the Flask server
if __name__ == "__main__":
app.run()