B
B
Bogdan2018-08-06 16:16:16
Facebook
Bogdan, 2018-08-06 16:16:16

Facebook bot not working Webhook?

Hello. Please tell me what could be the problem. Made a bot, subscribed to webhooks. But if you write messages from the page, then webhooks do not work (I made an output to the console), and if you make a test send in the bot settings, then everything works. I feel that somewhere some setting is missing, but which one?
Already tried putting the application in published mode, it did not help.
1. Create an application
5b6844505a410377136320.png
2. Create a new page for the bot
5b6844680123c907110638.png
3. Select a page and generate a token
5b684625e4a76162385018.png
4. Set up a webhook subscription
5b6846cd3dfa3037612608.png
5. Select a page to link the bot to
5b6846eb0be78617465410.png
6. Edit the subscription on the Webhook tab
5b6847108e508554165046.png
7. Set up the bot in the page settings.
5b68481596b79090334710.png
8. I send messages from the page and webhooks do not work (even in the ngork logs there is no message)
5b6849334827d205125592.png
9. I send a test message from the webhook settings and everything works.
5b6849ca1196c231461155.png
Here is the bot

const express = require('express');
const bodyParser = require('body-parser');
 
require('dotenv').config();
 
app = express();
 
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
 
 
app.get('/', (req, res) => res.send('Hello World!'));
 
// Добавление поддержки GET-запросов в webhook
app.get('/webhook', (req, res) => {
 
  // Токен верификации. Он должен быть строкой, состоящей из случайных символов
  let VERIFY_TOKEN = process.env.FB_VERIFY_TOKEN;
 
  // Разбор параметров запроса
  let mode = req.query['hub.mode'];
  let token = req.query['hub.verify_token'];
  let challenge = req.query['hub.challenge'];
 
  // Проверка, имеются ли в запросе mode и token
  if (mode && token) {
 
      // Проверка правильности mode и token
      if (mode === 'subscribe' && token === VERIFY_TOKEN) {
 
          // Отправка токена challenge из запроса
          console.log('WEBHOOK_VERIFIED');
          res.status(200).send(challenge);
 
      } else {
          // Отправка ответа '403 Forbidden' если верифицировать токен не удалось
          res.sendStatus(403);
      }
  }
});
    
app.post('/webhook', (req, res) => {
  console.log('WEBHOOK POST')
  res.status(200).send('EVENT_RECEIVED'); 
});
  
app.listen(process.env.APP_PORT, () => console.log(`Example app listening on port ${process.env.APP_PORT}!`));

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shadrinivan, 2020-06-19
@shadrinivan

I have the same problem, webhooks only come from the user who created the application to link the page. Everything is implemented on 1C and Apache server. Sent but received from the same user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question