Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
liciolentimo committed Sep 11, 2019
1 parent 257d535 commit bdb3ff8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3
WORKDIR /code
ENV FLASK_APP app.py
ENV FLASK_RUN_HOST 0.0.0.0
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["python","app.py"]
57 changes: 57 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from flask import Flask, request
import africastalking
import os

app = Flask(__name__)
username = "sandbox"
api_key = "f5b47ca7f37d37eab589b2ec1425211c53b373b7f8cec2a4e64ca653b49ee40b"
africastalking.initialize(username, api_key)

@app.route('/', methods=['POST', 'GET'])
def ussd_callback():
global response
session_id = request.values.get("sessionId",None)
service_code = request.values.get("serviceCode",None)
phone_number = request.values.get("phoneNumber",None)
print(phone_number)
text = request.values.get("text","default")
sms_phone_number = []
sms_phone_number.append(phone_number)

if text == "":
response = "CON What would you like to do?\n"
response += "1. Check account details\n"
response += "2. Check phone number\n"
response += "3. Send me a message"

elif text == "1":
response = "CON What would you like to check on your account?\n"
response += "1. Account number"
response += "2. Account balance"

elif text == "2":
response = "END Your phone number is {}".format(phone_number)

elif text == "3":
try:
sms_response = sms.send("Thank you for your response", sms_phone_number)
print(sms_response)
except Exception as e:
print(f"Licio, we have a problem: {e}")

elif text == "1*1":
account_number = "1243324376742"
response = "END Your account number is {}".format(account_number)

elif text == "1*2":
account_balance = "100,000"
response = "END Your account balance is KES {}".format(account_balance)

else:
response = "END Invalid input. Try again."

return response


if __name__ == "__main__":
app.run(host="0.0.0.0", port=os.environ.get("PORT"))
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
africastalking

0 comments on commit bdb3ff8

Please sign in to comment.