imseldrith commited on
Commit
e0834c3
·
verified ·
1 Parent(s): 80da867

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -1,11 +1,20 @@
1
  from flask import Flask, request, jsonify
2
  import requests
 
 
 
3
 
4
  app = Flask(__name__)
5
 
6
- VERIFY_TOKEN = 'imseldrith' # Replace with your verification token
7
- ACCESS_TOKEN = 'EAAHQjpHkOQQBO8d03L5jRIdplH7dOuYOFpTCYqVMU4QZA7HJbzP6pGICnCam6RF2zhfR7Hu8s7p5eKDH1Bjn84tm0ZBEA2CJCzu4UujsUUkGIZAuP7wNQVLs9OY34CsOixt5nkgi9zLPPFCGpAEEpo8dXZBXifQPOwGtma7FfWmP2AMpukODNfsfbv8SeA4K' # Replace with your Facebook Page Access Token
 
 
8
 
 
 
 
 
9
  @app.route('/', methods=['GET'])
10
  def home():
11
  return "Welcome to the chatbot!"
@@ -17,7 +26,7 @@ def webhook():
17
  verify_token = request.args.get('hub.verify_token')
18
  challenge = request.args.get('hub.challenge')
19
 
20
- print(f"GET request received: verify_token={verify_token}, challenge={challenge}")
21
 
22
  if verify_token == VERIFY_TOKEN:
23
  print("Verification token matches. Returning challenge.")
@@ -67,7 +76,7 @@ def send_message(recipient_id, message_text):
67
  print(f"Message send response: {response.status_code}, {response.text}")
68
 
69
  def set_typing_on(recipient_id):
70
- url = f'https://graph.facebook.com/v12.0/me/messages?access_token={ACCESS_TOKEN}'
71
  headers = {'Content-Type': 'application/json'}
72
  payload = {
73
  'recipient': {'id': recipient_id},
@@ -78,7 +87,7 @@ def set_typing_on(recipient_id):
78
  print(f"Typing on response: {response.status_code}, {response.text}")
79
 
80
  def set_typing_off(recipient_id):
81
- url = f'https://graph.facebook.com/v12.0/me/messages?access_token={ACCESS_TOKEN}'
82
  headers = {'Content-Type': 'application/json'}
83
  payload = {
84
  'recipient': {'id': recipient_id},
 
1
  from flask import Flask, request, jsonify
2
  import requests
3
+ from dotenv import load_dotenv
4
+
5
+ load_dotenv()
6
 
7
  app = Flask(__name__)
8
 
9
+ # Retrieve environment variables
10
+ 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
  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.")
 
76
  print(f"Message send response: {response.status_code}, {response.text}")
77
 
78
  def set_typing_on(recipient_id):
79
+ url = f'https://graph.facebook.com/v12.0/me/messages?access_token={PAGE_ACCESS_TOKEN}'
80
  headers = {'Content-Type': 'application/json'}
81
  payload = {
82
  'recipient': {'id': recipient_id},
 
87
  print(f"Typing on response: {response.status_code}, {response.text}")
88
 
89
  def set_typing_off(recipient_id):
90
+ url = f'https://graph.facebook.com/v12.0/me/messages?access_token={PAGE_ACCESS_TOKEN}'
91
  headers = {'Content-Type': 'application/json'}
92
  payload = {
93
  'recipient': {'id': recipient_id},