Initialize Webhook Server
If you want to receive incoming and outgoing messages, you need to install Webhook Listener. We have listed the steps for this respectively:
You need to obtain a tunnel address via NGROK. How do I do it?
You need to call and configure the webhookServer class in the WhatsappJS class.
An example is given below.
import { WhatsappJS } from '@efesoroglu/whatsappjs'
const client = new WhatsappJS("<your-api-key>", "<channel-phone-number>");
client.webhookServer({
port: 8080,
events: ["whatsapp.message.new"],
host_name: "https://<your_sub>.ngrok-free.app",
});
client.once('ready', (client) => {
console.log(`The bot started with the name ${client.friendly_name} (${client.phone_number})!`);
});
client.start();
Now you are ready and can listen to the events you have selected!
Last updated