-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (46 loc) · 1.6 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
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Ka beta perpendicular"
@app.route('/webhook', methods=['POST'])
def webhook():
req = request.get_json(silent=True, force=True)
sum = 0
query_result = req.get('queryResult')
print('-----')
print(query_result)
print('-----')
print(type(query_result))
print('-----')
# print(query_result.get('action'))
intentv1 = query_result.get('intent')
intentv2 = intentv1.get('displayName')
print('-----')
print(intentv1)
print('-----')
print(intentv2)
if intentv2 == 'add.numbers':
num1 = int(query_result.get('parameters').get('number'))
num2 = int(query_result.get('parameters').get('number1'))
sum = str(num1 + num2)
print('here num1 = {0}'.format(num1))
print('here num2 = {0}'.format(num2))
fulfillmentText = 'The sum of the two numbers is '+sum
# sum = str(num1 + num2)
# print('here num1 = {0}'.format(num1))
# print('here num2 = {0}'.format(num2))
if intentv2 == 'multiply.numbers':
num1 = int(query_result.get('parameters').get('number'))
num2 = int(query_result.get('parameters').get('number1'))
product = str(num1 * num2)
print('here num1 = {0}'.format(num1))
print('here num2 = {0}'.format(num2))
fulfillmentText = 'The product of the two numbers is '+product
return {
"fulfillmentText": fulfillmentText,
"displayText": '25',
"source": "webhookdata"
}
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)