-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
71 lines (57 loc) · 1.75 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, request, redirect
from twilio.twiml.messaging_response import MessagingResponse
from twilio.rest import Client
import json
import watson_developer_cloud
app = Flask(__name__)
def redzone():
redzone=["Weir","Library","Square","down town"]
return redzone
contexts=[]
@app.route("/bot", methods=['GET','POST'])
def bot_talk():
message=request.values.get('Body',None)
number=request.values.get('From',None)
twilioNumber = request.values.get('To')
context=None
index =0
contextIndex=0
for cont in contexts:
print(cont.get("From",None))
if cont.get("From",None)==number:
context=cont.get("Body",None)
contextIndex=index
index=index+1
print("Received Message from "+number+"saying " +message )
conversation = watson_developer_cloud.ConversationV1(
username='baa8a3a1-6dc1-4458-a23a-ce3115133ae2',
password='MD42bUyTN2CE',
version='2017-05-26')
response=conversation.message(workspace_id='1d7276eb-2bff-4e67-b8fc-8261df022546',
message_input={'text': message})
account_sid = "ACc5173ddda5dea6f7c9b4398c0f80d545"
auth_token = "87e59826d7f49301f6bebedf32d21d51"
client = Client(account_sid, auth_token)
try:
def new(response):
#resp=
if context == None:
contexts.append({'from': number, 'context': response.context})
else:
contexts[contextIndex].context = response.context
if response["intents"][0]['intent']=="Redzone":
apple =str(redzone())
else:
apple=response["output"]["text"][0]
message1 = client.messages.create(
to=number,
from_=twilioNumber,
body=apple)
except:
message1 = client.messages.create(
to=number,
from_=twilioNumber,
body="I dont understand")
# new(response)
if __name__ == "__main__":
app.run(debug=True)