-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (41 loc) · 1.3 KB
/
main.py
File metadata and controls
55 lines (41 loc) · 1.3 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
49
50
51
52
53
54
55
# Flask server for bot
from __future__ import print_function
import os
from flask import Flask, request
import requests
from maverickQA import MaverickQA
from maverickChat import MaverickGPT
app = Flask('app')
@app.route('/')
def load_server():
return 'Yay! server up and running! Users can now query MaverickAi!'
@app.route('/sms_callback', methods=['POST'])
def sms_callback():
print(request.form)
global sender, reply_to
sender = request.form['to']
reply_to = request.form['from']
if sender == '5959':
reply = MaverickQA(request.form['text'])
else: #59009
reply = MaverickGPT(request.form['text'])
#print(reply)
sms_response(reply_to, reply)
return 'success', 201
api_key = os.environ['at_api']
username = 'sandbox'
def sms_response(send_to, message):
print("sending back")
requests.post("https://api.sandbox.africastalking.com/version1/messaging",
data={
"username": username,
"to": send_to,
"message": message,
"from": sender,
},
headers={
"apiKey": api_key,
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
})
app.run(host='0.0.0.0', port=8080)