Neurolingua commited on
Commit
d173c0d
1 Parent(s): 53cf00e

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +6 -0
  2. app.py +60 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+ WORKDIR /code
3
+ COPY ./requirements.txt /code/requirements.txt
4
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
5
+ COPY . /code
6
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request
2
+ from twilio.twiml.messaging_response import MessagingResponse
3
+ from twilio.rest import Client
4
+ import os
5
+
6
+ # Initialize the Flask app
7
+ app = Flask(__name__)
8
+
9
+ # Twilio credentials
10
+ account_sid = 'AC97ad50edcf94fdd7d4576be9651bf4bf'
11
+ auth_token = '6d8b2559ffbbdbc5d06542e545220aaa'
12
+ client = Client(account_sid, auth_token)
13
+
14
+ # OpenAI API Key
15
+
16
+ # WhatsApp number to send messages from (your Twilio number)
17
+ from_whatsapp_number = 'whatsapp:+14155238886'
18
+
19
+ # Route to handle incoming WhatsApp messages
20
+ @app.route('/whatsapp', methods=['POST'])
21
+ def whatsapp_reply():
22
+ incoming_msg = request.values.get('Body', '').lower()
23
+ sender = request.values.get('From')
24
+
25
+ if 'bookkeeping' in incoming_msg:
26
+ response_text = "Please provide the details you'd like to record."
27
+ else:
28
+ response_text = get_agricultural_insights(incoming_msg)
29
+
30
+ send_message(sender, response_text)
31
+ return '', 204 # Return an empty response to Twilio
32
+
33
+ def get_agricultural_insights(query):
34
+
35
+ return "I'm sorry, I couldn't process that request. Please try again later."
36
+
37
+ def send_message(to, body):
38
+ try:
39
+ message = client.messages.create(
40
+ from_=from_whatsapp_number,
41
+ body=body,
42
+ to=to
43
+ )
44
+ print(f"Message sent with SID: {message.sid}")
45
+ except Exception as e:
46
+ print(f"Error sending message: {e}")
47
+
48
+ # Function to send an initial message
49
+ def send_initial_message(to_number):
50
+ send_message(
51
+ f'whatsapp:{to_number}',
52
+ 'Welcome to the Agri AI Chatbot! How can I assist you today?'
53
+ )
54
+
55
+ if __name__ == '__main__':
56
+ # Send an initial message when the script starts
57
+ send_initial_message('916382792828') # Replace with the recipient's number
58
+
59
+ # Start the Flask server
60
+ app.run(host='0.0.0.0', port=7860)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask
2
+ twilio
3
+ openai