Spaces:
Sleeping
Sleeping
imseldrith
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -16,22 +16,35 @@ def webhook():
|
|
16 |
verify_token = request.args.get('hub.verify_token')
|
17 |
challenge = request.args.get('hub.challenge')
|
18 |
|
|
|
|
|
19 |
if verify_token == VERIFY_TOKEN:
|
|
|
20 |
return challenge
|
21 |
else:
|
|
|
22 |
return 'Error, wrong validation token'
|
23 |
|
24 |
elif request.method == 'POST':
|
25 |
data = request.get_json()
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
sender_id = messaging_event['sender']['id']
|
30 |
-
message_text = messaging_event['message'].get('text', '')
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
35 |
|
36 |
return jsonify({'status': 'ok'})
|
37 |
|
@@ -43,7 +56,9 @@ def send_message(recipient_id, message_text):
|
|
43 |
'recipient': {'id': recipient_id},
|
44 |
'message': {'text': message_text}
|
45 |
}
|
46 |
-
|
|
|
|
|
47 |
|
48 |
if __name__ == '__main__':
|
49 |
app.run(host="0.0.0.0", port=7860, debug=True)
|
|
|
16 |
verify_token = request.args.get('hub.verify_token')
|
17 |
challenge = request.args.get('hub.challenge')
|
18 |
|
19 |
+
print(f"GET request received: verify_token={verify_token}, challenge={challenge}")
|
20 |
+
|
21 |
if verify_token == VERIFY_TOKEN:
|
22 |
+
print("Verification token matches. Returning challenge.")
|
23 |
return challenge
|
24 |
else:
|
25 |
+
print("Error: wrong validation token.")
|
26 |
return 'Error, wrong validation token'
|
27 |
|
28 |
elif request.method == 'POST':
|
29 |
data = request.get_json()
|
30 |
+
print(f"POST request received: {data}")
|
31 |
+
|
32 |
+
if 'entry' in data and len(data['entry']) > 0 and 'messaging' in data['entry'][0]:
|
33 |
+
messaging_event = data['entry'][0]['messaging'][0]
|
34 |
+
print(f"Messaging event: {messaging_event}")
|
35 |
+
|
36 |
+
if 'message' in messaging_event:
|
37 |
+
sender_id = messaging_event['sender']['id']
|
38 |
+
message_text = messaging_event['message'].get('text', '')
|
39 |
|
40 |
+
print(f"Received message from {sender_id}: {message_text}")
|
|
|
|
|
41 |
|
42 |
+
if message_text.lower() == 'hi':
|
43 |
+
response_text = 'hello'
|
44 |
+
print(f"Sending response to {sender_id}: {response_text}")
|
45 |
+
send_message(sender_id, response_text)
|
46 |
+
else:
|
47 |
+
print(f"No action taken for message: {message_text}")
|
48 |
|
49 |
return jsonify({'status': 'ok'})
|
50 |
|
|
|
56 |
'recipient': {'id': recipient_id},
|
57 |
'message': {'text': message_text}
|
58 |
}
|
59 |
+
print(f"Sending message request: {payload}")
|
60 |
+
response = requests.post(url, headers=headers, json=payload)
|
61 |
+
print(f"Message send response: {response.status_code}, {response.text}")
|
62 |
|
63 |
if __name__ == '__main__':
|
64 |
app.run(host="0.0.0.0", port=7860, debug=True)
|