tawn33y / whatsapp-cloud-api

A Node.js library for creating bots and sending/receiving messages using the Whatsapp Cloud API.
https://www.npmjs.com/package/whatsapp-cloud-api
GNU General Public License v3.0
189 stars 51 forks source link

How to unregister (kill) a bot? #54

Closed techpet closed 1 year ago

techpet commented 1 year ago

I am trying to accomplish a multibot configuration in which bots could be created and deleted dynamically. Is there a way to destroy a bot or even unregister its webhookPath?

tawn33y commented 1 year ago

You can now use the following functionality to remove a listener for a specific bot:

(async () => {
  const bot = createBot('from', 'token');
  await bot.startExpressServer({ webhookVerifyToken: 'xx' });

  const subscriptionToken = bot.on('message', async (msg) => {
    console.log(msg);
  });

  // to unsubscribe:  
  bot.unsubscribe(subscriptionToken);
})();