imseldrith commited on
Commit
cf9fdca
·
verified ·
1 Parent(s): fa795f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -2,6 +2,8 @@ from flask import Flask, request, jsonify
2
  import requests
3
  from dotenv import load_dotenv
4
  import os
 
 
5
  load_dotenv()
6
 
7
  app = Flask(__name__)
@@ -11,10 +13,11 @@ VERIFY_TOKEN = os.getenv('VERIFY_TOKEN')
11
  PAGE_ACCESS_TOKEN = os.getenv('PAGE_ACCESS_TOKEN')
12
  OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
13
 
14
- # Debugging: Print the loaded environment variables
15
  print(f"VERIFY_TOKEN: {VERIFY_TOKEN}")
16
  print(f"PAGE_ACCESS_TOKEN: {PAGE_ACCESS_TOKEN}")
17
  print(f"OPENAI_API_KEY: {OPENAI_API_KEY}")
 
18
  @app.route('/', methods=['GET'])
19
  def home():
20
  return "Welcome to the chatbot!"
@@ -26,7 +29,7 @@ def webhook():
26
  verify_token = request.args.get('hub.verify_token')
27
  challenge = request.args.get('hub.challenge')
28
 
29
- print(f"GET request received: verify_token={VERIFY_TOKEN}, challenge={challenge}")
30
 
31
  if verify_token == VERIFY_TOKEN:
32
  print("Verification token matches. Returning challenge.")
@@ -65,7 +68,7 @@ def webhook():
65
  return jsonify({'status': 'ok'})
66
 
67
  def send_message(recipient_id, message_text):
68
- url = f'https://graph.facebook.com/v12.0/me/messages?access_token={ACCESS_TOKEN}'
69
  headers = {'Content-Type': 'application/json'}
70
  payload = {
71
  'recipient': {'id': recipient_id},
@@ -98,4 +101,4 @@ def set_typing_off(recipient_id):
98
  print(f"Typing off response: {response.status_code}, {response.text}")
99
 
100
  if __name__ == '__main__':
101
- app.run(host="0.0.0.0", port=7860, debug=True)
 
2
  import requests
3
  from dotenv import load_dotenv
4
  import os
5
+
6
+ # Load environment variables from .env file
7
  load_dotenv()
8
 
9
  app = Flask(__name__)
 
13
  PAGE_ACCESS_TOKEN = os.getenv('PAGE_ACCESS_TOKEN')
14
  OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
15
 
16
+ # Debugging: Print the loaded environment variables (remove in production)
17
  print(f"VERIFY_TOKEN: {VERIFY_TOKEN}")
18
  print(f"PAGE_ACCESS_TOKEN: {PAGE_ACCESS_TOKEN}")
19
  print(f"OPENAI_API_KEY: {OPENAI_API_KEY}")
20
+
21
  @app.route('/', methods=['GET'])
22
  def home():
23
  return "Welcome to the chatbot!"
 
29
  verify_token = request.args.get('hub.verify_token')
30
  challenge = request.args.get('hub.challenge')
31
 
32
+ print(f"GET request received: verify_token={verify_token}, challenge={challenge}")
33
 
34
  if verify_token == VERIFY_TOKEN:
35
  print("Verification token matches. Returning challenge.")
 
68
  return jsonify({'status': 'ok'})
69
 
70
  def send_message(recipient_id, message_text):
71
+ url = f'https://graph.facebook.com/v12.0/me/messages?access_token={PAGE_ACCESS_TOKEN}'
72
  headers = {'Content-Type': 'application/json'}
73
  payload = {
74
  'recipient': {'id': recipient_id},
 
101
  print(f"Typing off response: {response.status_code}, {response.text}")
102
 
103
  if __name__ == '__main__':
104
+ app.run(host="0.0.0.0", port=7860, debug=True)