-
Notifications
You must be signed in to change notification settings - Fork 3
/
twilio_handle.py
40 lines (32 loc) · 1.37 KB
/
twilio_handle.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
37
38
39
40
import os
from flask import Flask, request
# from twilio import twiml
#from twilio.rest import TwilioRestClient
from slackclient import SlackClient
from controller import controller
control = controller()
AT_BOT = "<@" + os.environ["bot_id"] + ">"
twilio_number = os.environ.get("twilio_number")
accept_number = os.environ.get("user_number")
app = Flask(__name__)
#twilio_client = TwilioRestClient()
slack_client = SlackClient(os.environ.get("slacktoken", None))
@app.route("/twilio", methods=['POST'])
def post_to_slack():
print "hit flask" + request.form['Body']
# response = twiml.Response()
if request.form['From'] in accept_number:
message = request.form['Body']
slack_client.api_call("chat.postMessage",
channel="#testonebotchanel",
text=AT_BOT +" "+ message, as_user=True)
#twilio_client.messages.create(to=accept_number, from_=twilio_number,body="response")
# return Response(response.toxml(), mimetype="text/xml"), 200
return '', 200
@app.route("/alexa_endpoint/<question>", methods=['GET'])
def return_to_alexa(question):
print "hit flask" + question.replace("_", " ")
return control.find_solution(question.replace("_", " ")).replace("\n", ". ")
if __name__ == "__main__":
heroku_port = int(os.environ.get("PORT", 6000))
app.run(host='0.0.0.0', port=heroku_port)