/viber_bot

Viber Chat Bot for current BTC and ETH prices

Primary LanguageJavaScript

CodeQL scan CircleCI DeepScan grade

Crypto Chatbot

Software Requirements

  • Viber Bot 1.0+
  • Node.js 14+
  • MongoDB 4.0+
  • Mongoose 5.13+
  • Bootstrap 5.1+
  • Express.js 4.17+

Project structure

.
├── app.js
├── package.json
├── package-lock.json
├── README.md
├── .gitignore
├── i18n.config.js
├── idle.js
├── jest.config.js
├── Procfile
├── publicUrl.js
├── scheduler.js
└── .circleci
│   |   └── config.yml
└── .github
│   ├── workflows
│   |   └── codeql.yml
└── locales
│   ├── bg.json
│   └── en.json
└── src
│   └── api
│   |   ├── crypto.api.js
│   |   └── users.api.js
│   └── config
│   |   ├── bot.config.js
│   |   ├── database.config.js
│   |   ├── express.config.js
│   |   ├── router.config.js
│   |   └── settings.config.js
│   └── constants
│   |   ├── request.headers.js
│   |   ├── request.message.js
│   |   ├── request.method.js
│   |   ├── request.url.js
│   |   └── response.message.js
│   └── controllers
│   |   ├── bot.controller.js
│   |   ├── consolidator.js
│   |   ├── event.controller.js
│   |   └── msg.controller.js
│   └── helpers
│   |   ├── common.ops.helper.js
│   |   └── request.helper.js
│   └── models
│   |   ├── bitcoin.model.js
│   |   ├── ethereum.model.js
│   |   └── user.model.js
│   ├── msgJsonTemplates
│   |   ├── keyboard.message.json
│   |   ├── rich-media.message.json
│   |   └── welcome.message.json
│   ├── services
│   |   └── locale.service.js
└── static
│   ├── images
│   └── styles
└── tests
│   ├── mock
│   ├── unit
│   └── integration
└── views
    ├── home
    └── layouts

Create Viber Public Account

https://partners.viber.com/account/create-bot-account

Developer Documentation

https://developers.viber.com/docs/

Node.JS Bot API => https://developers.viber.com/docs/api/nodejs-bot-api/

For Node.JS,

Create a file .env in main directory and add this below text

VIBER_ACCESS_TOKEN=Your Viber Access Token Add HERE
MONGODB_URI=Your Mongo DB Connection String Add Here
WEBHOOK_URL=Your Heroku URL like https://yourappname.herokuapp.com
PORT=3000

For local testing

Install ngrok globally with command

npm install -g ngrok

Clone project with

git clone https://github.com/YavorGrancharov/viber_bot.git

Install all dependencies with

npm install

Then, inside app.js file, replace this block of code:

app.listen(settings.port, async () => {
  try {
    console.log(`Application running on port: ${settings.port}`);
    bot.setWebhook(`${process.env.WEBHOOK_URL}/viber/webhook`);
  } catch (error) {
    console.log('Can not set webhook on following server.');
    console.error(error);
    process.exit(1);
  }
});

with this one:

app.listen(settings.port, async () => {
  try {
    const publicUrl = await getPublicUrl();
    console.log(`Application running on port: ${settings.port}`);
    console.log('publicUrl => ', publicUrl);
    bot.setWebhook(`${publicUrl}/viber/webhook`);
  } catch (error) {
    console.log('Can not set webhook on following server.');
    console.error(error);
    process.exit(1);
  }
});

and run project using commands npm run ngrok and npm run start on two separate terminals

You can see it running on localhost:3000

You can visit bot's home page by following link below

Crypto Chatbot

Run all tests with command

npm run test

Technology Stack

Contributors