Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
El código que funciona en el servidor da un error cuando se ejecuta en localhost

Para recrear el código simplemente siga este artículo

El código final es:

 'use strict'; // Imports dependencies and set up http server const express = require('express'), bodyParser = require('body-parser'), app = express().use(bodyParser.json()); // creates express http server // Sets server port and logs message on success app.listen(process.env.PORT || 1337, () => console.log('webhook is listening')); // Creates the endpoint for our webhook app.post('/webhook', (req, res) => { let body = req.body; // Checks this is an event from a page subscription if (body.object === 'page') { // Iterates over each entry - there may be multiple if batched body.entry.forEach(function(entry) { // Gets the message. entry.messaging is an array, but // will only ever contain one message, so we get index 0 let webhook_event = entry.messaging[0]; console.log(webhook_event); }); // Returns a '200 OK' response to all requests res.status(200).send('EVENT_RECEIVED'); } else { // Returns a '404 Not Found' if event is not from a page subscription res.sendStatus(404); } }); app.get('/webhook', (req, res) => { // Your verify token. Should be a random string. let VERIFY_TOKEN = "<YOUR_VERIFY_TOKEN>" // Parse the query params let mode = req.query['hub.mode']; let token = req.query['hub.verify_token']; let challenge = req.query['hub.challenge']; // Checks if a token and mode is in the query string of the request if (mode && token) { // Checks the mode and token sent is correct if (mode === 'subscribe' && token === VERIFY_TOKEN) { // Responds with the challenge token from the request console.log('WEBHOOK_VERIFIED'); res.status(200).send(challenge); } else { // Responds with '403 Forbidden' if verify tokens do not match res.sendStatus(403); } } });

Obtener la ruta de solicitud funciona bien, pero cuando presiono la publicación con esta solicitud

 curl -H "Content-Type: application/json" -X POST "localhost:1337/webhook" -d '{"object": "page", "entry": [{"messaging": [{"message": "TEST_MESSAGE"}]}]}'

Recibo este error a pesar de que un json es válido

 SyntaxError: Unexpected token o in JSON at position 1

Es bastante inesperado para mí, este código funciona en el servidor con la misma versión de nodo instalada: 14.7.6

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda