aboutsummaryrefslogtreecommitdiffstats
path: root/slack.py
blob: e31061d1d293d482afc92aec381dcbe66f6d84f0 (plain)
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
from flask import Flask, jsonify, request
from xkcd import get_xkcd
app = Flask(__name__)
app.config.from_envvar('CONF')

@app.route("/echo", methods=['POST'])
def echo():
    d = {'response_type': 'in_channel',
         'text': "I'm the echo bot!",
         'attachments': [
             {'text':request.form['text']}
         ]
    }
    return jsonify(d)

@app.route("/xkcd", methods=['POST'])
def xkcd_view():
    comic_id = request.form['text']
    title, url = get_xkcd(comic_id)
    d = {'response_type': 'in_channel',
         'attachments': [
             {'image_url':"http:{0}".format(url),
              'title': title,
              'title_link': 'http://www.xkcd.org/{0}'.format(comic_id)
             }
         ]
    }
    return jsonify(d)

if __name__=="__main__":
    app.run()