-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.py
36 lines (27 loc) · 794 Bytes
/
app.py
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
import os
import sys
import json
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
def webhook():
data = request.get_json()
log('Recieved {}'.format(data))
# We don't want to reply to ourselves!
if data['name'] != 'apnorton-test-bot':
msg = '{}, you sent "{}".'.format(data['name'], data['text'])
send_message(msg)
return "ok", 200
def send_message(msg):
url = 'https://api.groupme.com/v3/bots/post'
data = {
'bot_id' : os.getenv('GROUPME_BOT_ID'),
'text' : msg,
}
request = Request(url, urlencode(data).encode())
json = urlopen(request).read().decode()
def log(msg):
print(str(msg))
sys.stdout.flush()