-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
104 lines (82 loc) · 3.51 KB
/
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
import os
import random
from flask import (
Flask,
request,
make_response,
jsonify
)
app = Flask(__name__)
log = app.logger
@app.route('/webhook', methods=['POST'])
def webhook():
req = request.get_json(silent=True, force=True)
action = req.get("result").get('action')
if action == 'transfer.money':
res = countryCheck(req)
elif action == 'transfer.money_service.info':
res = directRemitYes(req)
elif action == 'transfer.money_service.info_country':
res = directRemitCountry(req)
elif action == 'support.transfer.amount':
res = directRemitCountryAmount(req)
else:
log.error("Unexpeted action.")
return make_response(jsonify(res))
def countryCheck(req):
speech = req['result']['fulfillment']['speech']
country = req['result']['parameters']['country']
country_list_prohibited = ['Iran', 'North Korea']
country_list_direct = ['India', 'Pakistan', 'Sri Lanka', 'Philippines', 'Egypt']
if country not in country_list_prohibited + country_list_direct:
speech = 'You can send money to '+country+' using our international money transfer service. Please refer to the <URL> for more information. Can I help you with something else?'
contexts = {}
elif country in country_list_prohibited:
speech = 'Sorry we are not able to transfer money to '+country+'. Can I help you with something else?'
contexts = {}
elif country in country_list_direct:
speech = 'You can use Direct Remit to transfer money to '+country+'. Would you like to know more?'
contexts = {
"name": "service-info",
"lifespan": 3,
"parameters": {
'country': country
}
}
return {
"speech": speech,
"displayText": speech,
"contextOut": [contexts]
}
def directRemitYes(req):
contexts = req['result']['contexts'][0]['parameters']
speech = 'DirectRemit is free service that allows you to transfer money in 60 seconds. You can ask me more about Direct Remit to ' + contexts['country'] + '.'
return {
"speech": speech,
"displayText": speech
}
def directRemitCountry(req):
contexts = req['result']['contexts'][0]['parameters']
speech = 'You can send a maximum of upto INR 5,000,000 to '+contexts['country']+' for Direct Remit.'
return {
"speech": speech,
"displayText": speech
}
def directRemitCountryAmount(req):
quantity = req['result']['parameters']['amount']
if quantity == 'max':
speech = 'Your Segment limit applicable for DirectRemit to India is detailed below:\n\n- Personal Banking AED 200,000\n- Private Banking AED 500,000\nThe maximum remittance amount for DirectRemit to Philippines is PHP 500,000 per transaction across segments. The maximum remittance for DirectRemit to Pakistan is PKR 500,000 per transaction across segments. The maximum remittance for DirectRemit to Sri Lanka is LKR 1,000,000 per transaction across segments. The maximum remittance for DirectRemit to Egypt is EGP 100,000 per transaction across segments'
elif quantity == 'min':
speech = 'An equivalent of AED 100 in the respective home currency is the minimum amount that can be transferred via DirectRemit.'
return {
"speech": speech,
"displayText": speech
}
if __name__ == '__main__':
port = int(os.getenv('PORT', 5000))
app.run(
debug=True,
port=port,
host='0.0.0.0'
)