3 from flask import Flask, request
4 from slackeventsapi import SlackEventAdapter
5 from turbot.slack import slack_is_valid_request, slack_send_reply
8 from turbot.rot import rot
9 from turbot.slack import slack_send_message
10 from turbot.sheets import sheets_create
14 slack_signing_secret = os.environ['SLACK_SIGNING_SECRET']
15 slack_events = SlackEventAdapter(slack_signing_secret, "/slack/events", app)
17 @app.route('/rot', methods = ['POST'])
19 """Implements the /rot slash command for Slack replying in Slack
21 The format of this command is as follows:
23 /rot [count|*] String to be rotated
25 The optional count indicates an amount to rotate each character in the
26 string. If the count is '*' or is not present, then the string will
27 be rotated through all possible 25 values.
29 The result of the rotation is provided as a message in Slack. If the
30 slash command was issued in a direct message, the response is made by
31 using the "response_url" from the request. This allows the bot to reply
32 in a direct message that it is not a member of. Otherwise, if the slash
33 command was issued in a channel, the bot will reply in that channel."""
35 if not slack_is_valid_request(request):
36 return make_response("invalid request", 403)
38 text = request.form.get('text')
42 slack_send_reply(request, reply)
47 @slack_events.on("channel_created")
48 def handle_channel_created(event_data):
50 sheet_url = sheets_create(channel["name"])
51 slack_send_message(channel["id"],
52 "Auto-created a sheet for this channel: {}"
55 event = event_data["event"]
56 channel = event["channel"]
57 thread = threading.Thread(target=later, kwargs={'channel': channel})
61 @slack_events.on("error")
62 def handle_error(error):
63 app.logger.error("Error from Slack: " + str(error))