How to setup a viberbot webhook for heroku deployed nodejs bot?

1k Views Asked by At

I have problem of setting up web hook for my chat bot i made using nodejs. Which is deployed on Heroku.

The app uses the following architecture :

const http = require('http');
const port = process.env.PORT || 8080;
 
// Viber will push messages sent to this URL. Web server should be internet-facing.
const webhookUrl = process.env.WEBHOOK_URL; 

// I have used this as Heroku app name with https://dyno-125-92.herokuapp.com

http.createServer(ot.middleware()).listen(port, () => bot.setWebhook(webhookUrl));

Please, help me to setup a webhook using express or anything that can work with my bot?
I'm stuck.

1

There are 1 best solutions below

1
On

Try this:

const express = require('express');
const app = express();

// contains relative URL path, like: "/viber/webhook"
const webhookUrl = process.env.WEBHOOK_URL;

// ...

app.use(webhookUrl, bot.middleware());
app.listen(port, () => {
  console.log(`Application running on port: ${port}`);
  bot.setWebhook(`${process.env.EXPOSE_URL}${webhookUrl}`).catch(error => {
    console.log('Can not set webhook on following server. Is it running?');
    console.error(error);
    process.exit(1);
  });
});

If it doesn't work, use - full code example to check.