Could not find bot account token key, viber bot, node.js

329 Views Asked by At

I am kinda new to node.js and stackoverflow, but I am having some troubles with creating a viber bot. Using this https://chatbotslife.com/build-viber-bot-with-nodejs-a21487e5b65, created viber API but cannot find where do I place my API inside code.

const ViberBot = require('viber-bot').Bot,
  BotEvents = require('viber-bot').Events,
  TextMessage = require('viber-bot').Message.Text,
  express = require('express');
const app = express();

if (!process.env.BOT_ACCOUNT_TOKEN) {
  console.log('Could not find bot account token key.');
  return;
}
if (!process.env.EXPOSE_URL) {
  console.log('Could not find exposing url');
  return;
}

const bot = new ViberBot({
  authToken: process.env.BOT_ACCOUNT_TOKEN,
  name: "Quest Bot",
  avatar: "https://upload.wikimedia.org/wikipedia/commons/9/93/BirthdayQuest.jpg"
});
bot.on(BotEvents.SUBSCRIBED, response => {
  response.send(new TextMessage(`Hi there ${response.userProfile.name}. I am ${bot.name}! Feel free to ask me anything.`));
});
bot.on(BotEvents.MESSAGE_RECEIVED, (message, response) => {
  response.send(new TextMessage(`Message received.`));
});
const port = process.env.PORT || 3000;
app.use("/viber/webhook", bot.middleware());
app.listen(port, () => {
  console.log(`Application running on port: ${port}`);
  bot.setWebhook(`${process.env.EXPOSE_URL}/viber/webhook`).catch(error => {
    console.log('Can not set webhook on following server. Is it running?');
    console.error(error);
    process.exit(1);
  });
});
1

There are 1 best solutions below

0
On

Try to make a variable first with single quotes 'including your API key here'

const bot_account = 'API KEY'

And then initialize your bot

 const bot = new ViberBot({
      authToken: bot_account,
      name: "Quest Bot",
      avatar: "https://upload.wikimedia.org/wikipedia/commons/9/93/BirthdayQuest.jpg"
    });

if your system has a PATH variable set, this will be made accessible to you through process.env.PATH which you can use to check where binaries are located and make external calls to them if required. source

In your case there is no path, so try allocating via variable.