-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
32 lines (24 loc) · 828 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
import os
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()
textToParse = data['text'].lower()
# We don't want to reply to ourselves!
if data['name'] != 'Friendly Neighborhood Bot':
if any(x in textToParse for x in ['group chat', ' gc']):
msg = 'Speaking of group chats, check out the group chat list: https://bit.ly/2FuzbPs'
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()