Closed KevinJoseph closed 1 year ago
You need to supply the app
value to the function for creating the server, ie:
await bot.startExpressServer({
// add this:
app,
webhookVerifyToken: process.env.VERIFY_TOKEN,
port: process.env.PORT || 2040,
webhookPath: '/webhook',
});
Also, nit, perhaps you can move the async definition to the top, i.e:
(async function() {
const app = express();
// ...
app.get('/hello', (req, res) => {
res.send('Hello World!')
})
})()
Thank you very much, is it possible to integrate socket io too?
On Sun, Jan 1, 2023, 2:00 AM Tony @.***> wrote:
You need to supply the app value to the function for creating the server, ie:
await bot.startExpressServer({ // Add this: app, webhookVerifyToken: process.env.VERIFY_TOKEN,port: process.env.PORT || 2040,webhookPath: /webhook,});
Also, nit, perhaps you can move the async definition to the top, i.e:
(async function() { const app = express();// ... app.get('/hello', (req, res) => {res.send('Hello World!')})})()
— Reply to this email directly, view it on GitHub https://github.com/tawn33y/whatsapp-cloud-api/issues/47#issuecomment-1368368940, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD74MWGSYJF6VVLRQY7OQYTWQETR5ANCNFSM6AAAAAATN2QECI . You are receiving this because you authored the thread.Message ID: @.***>
Thank you very much, is it possible to integrate socket io too?
Most welcome.
Unsure why you would need socket.io since you won't be able to integrate it with the Whatsapp app. Unless if you mean integration with your own service (e.g. your own frontend), then yes, you can definitely do it.
That's right, I want to integrate it with my own interface
I am developing it this way but the app stops. const from = process.env.WHATSAPP_PHONE_NUMBER_ID; const token = process.env.WHATSAPP_TOKEN; const webhookVerifyToken = process.env.VERIFY_TOKEN; const bot = createBot(from, token);
(async function() { const app = express();
// ...
app.get('/hello', (req, res) => { res.send('Hello World!') })
await bot.startExpressServer({
// add this:
app,
webhookVerifyToken: process.env.VERIFY_TOKEN,
port: process.env.PORT || 2040,
webhookPath: '/webhook',
}); })()
If I comment these lines of the file, startExpressServer.js executes me correctly
Hi @KevinJoseph, Did you manage to fix this?
Can you clarify what you mean by If I comment these lines of the file
; which lines specifically?
Closing this due to insufficient info. @KevinJoseph, feel free to reopen :)
Hi, I'm starting the following:
const { createBot } = require('whatsapp-cloud-api'); const axios = require('axios'); const express = require('express');
const app = express();
const from = process.env.WHATSAPP_PHONE_NUMBER_ID; const token = process.env.WHATSAPP_TOKEN; const webhookVerifyToken = process.env.VERIFY_TOKEN;
// Create a bot that can send messages const bot = createBot(from, token); (async function() { await bot.startExpressServer({ webhookVerifyToken: process.env.VERIFY_TOKEN, port: process.env.PORT || 2040, webhookPath:
/webhook
, }); })();app.get('/hello', (req, res) => { res.send('Hello World!') }) but when consulting the /hello route it gives me 404 as a result, is there an error with the route handler? thank you