Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import logging
2
- import ssl
3
  import smtplib
4
  import re
5
  from email.mime.text import MIMEText
@@ -28,6 +27,7 @@ conversations = {}
28
  EMAIL_REGEX = re.compile(r"^[^@]+@[^@]+\.[^@]+$")
29
 
30
  def validate_email(email: str) -> bool:
 
31
  return re.match(EMAIL_REGEX, email) is not None
32
 
33
  def send_email(from_addr: str, to_addr: str, subject: str, body: str) -> bool:
@@ -68,8 +68,7 @@ def bot():
68
  try:
69
  data = request.json
70
  sender_number = data.get("from", "unknown")
71
- # Use the message body from WhatsApp (trim any extra spaces)
72
- message_body = data.get("text", {}).get("body", "").strip()
73
  except Exception as e:
74
  logger.error("Invalid JSON payload: %s", e)
75
  return jsonify({"status": "error", "message": "Invalid payload"}), 400
@@ -119,4 +118,4 @@ def bot():
119
  return jsonify({"status": "success", "message": response_msg})
120
 
121
  if __name__ == "__main__":
122
- app.run(host="0.0.0.0", port=5000)
 
1
  import logging
 
2
  import smtplib
3
  import re
4
  from email.mime.text import MIMEText
 
27
  EMAIL_REGEX = re.compile(r"^[^@]+@[^@]+\.[^@]+$")
28
 
29
  def validate_email(email: str) -> bool:
30
+ """Validate an email address using regex."""
31
  return re.match(EMAIL_REGEX, email) is not None
32
 
33
  def send_email(from_addr: str, to_addr: str, subject: str, body: str) -> bool:
 
68
  try:
69
  data = request.json
70
  sender_number = data.get("from", "unknown")
71
+ message_body = data.get("message", {}).get("text", {}).get("body", "").strip()
 
72
  except Exception as e:
73
  logger.error("Invalid JSON payload: %s", e)
74
  return jsonify({"status": "error", "message": "Invalid payload"}), 400
 
118
  return jsonify({"status": "success", "message": response_msg})
119
 
120
  if __name__ == "__main__":
121
+ app.run(host="0.0.0.0", port=5000)