В настоящее время я создаю чат-бота в мессенджере Facebook и пытаюсь реализовать поток «одноразового уведомления».
Я могу успешно спросить пользователя, хотят ли они получать уведомление, но я никогда не получаю пингбэков на свой вебхук. Я убедился, что мой вебхук подписан на события optin, но все равно ничего. Я также убедился, что моя страница имеет доступ к функции одноразового уведомления.
Я попробовал проверить разрешения для всей моей учетной записи Facebook, полагая, что это, должно быть, ошибка на стороне Facebook, потому что не отправляю ответ на вебхук, но не могу разобраться. Я также несколько раз пытался реализовать это с нуля, чтобы проверить, не пропустил ли я где-нибудь какой-то шаг, но никаких изменений.
Разрешения страниц. Подписки на веб-перехватчики
Вот как я получаю запрос:
def handle_message(self, request):
data = request.get_json()
if data['object'] == "page":
for entry in data['entry']:
for messaging_event in entry['messaging']:
sender_id = messaging_event['sender']['id']
if messaging_event.get('optin'):
print('Optin event recieved!!!')
token = messaging_event['optin']['one_time_notif_token']
# Check for postback and handle it
elif 'postback' in messaging_event:
payload = messaging_event['postback']['payload']
self.handle_payload(sender_id, payload)
# Check for quick_reply and handle it
elif 'message' in messaging_event and 'quick_reply' in messaging_event['message']:
payload = messaging_event['message']['quick_reply']['payload']
self.handle_payload(sender_id, payload)
# Handle regular text messages
elif 'message' in messaging_event:
message_text = messaging_event['message'].get('text', '')
print("Message from {}: {}".format(sender_id, message_text))
response_text = self.chatgpt.get_chat_response(message_text)
self.send_message(sender_id, response_text)
return jsonify({'success': True}), 200
Вот код отправки запроса:
def send_otn_request(recipient_id, page_access_token):
headers = {
'Content-Type': 'application/json'
}
data = {
"recipient": {
"id": recipient_id
},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "one_time_notif_req",
"title": "Want us to remind you of your appointment?",
"payload": "YES_REMINDER" # Payload to track the type of notification
}
}
}
}
print(f"Sending OTN request to recipient: {recipient_id}")
print(f"Request headers: {headers}")
print(f"Request data: {data}")
response = requests.post(
f'https://graph.facebook.com/v14.0/me/mes ... cess_token}',
headers=headers,
json=data
)
print(f"OTN request response: {response.status_code}, {response.text}")
# Check for errors in the response
if response.status_code != 200:
print(f"Error sending OTN request: {response.text}")
else:
print("OTN request sent successfully!")
return response.json()
Подробнее здесь: https://stackoverflow.com/questions/787 ... ion-otn-re