R4dar / InteligenciaColetivaBot

Assistente virtual - na forma de um chatbot, que vem "embutido" ao Radar e é responsável pela configuração dos algorítmos
Other
2 stars 2 forks source link

assistente

build status Coverage Status Codefresh build status

assistente-backend

About

This project uses Feathers. An open source web framework for building modern real-time applications.

See Docs for many information

Setup and Building

Docker

The Dockerfile is an alpine-aarch64 based image node.js, yarn and localtunnel.

Change the section FROM ... to fit your needs. The following command runs the default configuration:

$ docker run -t lunhg/assistente

But you can change:

$ docker run -t lunhg/assistente HOST=localhost PORT=3000 SUBDOMAIN=r4dar

Manually

Install dependencies first with npm or yarn.

Node Package manager

npm install

Yarn (recomended)

yarn install

In your package.json, set the running mode, i.e, development, test, production or custom mode:

{
  ...
  "scripts": {
    "start": "NODE_ENV='<environment mode>' node src/"
  } 
  ...
}

Where, <environment mode> can be any json file found in config/ folder. These files are a set of configurations for database, express, passport, telegram, cookies, jwt and swagger. The default.json file is relative to development mode:

Among serveral configurations made by default, you will need to setup some credentials:

So, cp .env.template .env and do properly changes:

TELEGRAM_USERNAME=<BOT> 
TELEGRAM_TOKEN=<TOKEN>
TELEGRAM_ADMINS="<chaid 1> <chatid 2> <chatid 3>"
MONGODB_USER=<user>
MONGODB_PWD=<pwd>
MONGODB_HOST=<host>
MONGODB_PORT=<port>
MONGODB_DBNAME=<name>
OPENID_CLIENT_ID=<clientid>
OPENID_CLIENT_SECRET=<clientsecret>
AUDIENCE=<your bot domain>
AUTHENTICATION_SECRET=<senha de cookie>

and add the following variables: HOST, PORT and AUDIENCE.

Running
Database

If you are using a local server, starts the database with authentication

$ sudo mongod --dbpath /data/db [...args] &

If you are using a remote database, simply insert the adequated credentials in environment variables. The variables started with MONGODB_* will be joined to MONGODB_URL (see src/dotenv.js).

Server
$ npm run start
Telegram and remote access

This server will use src/views/index.tml (tml is a customized html template with properly environment variables inserted in html and js code) as GET /.

If you run and access this as localhost:*, you will see a Bot domain invalid message in the place of telegram button.

To solve this, you will need to run a valid domain name to the bot and place this as AUDIENCE variable in .env file, and run a tunnel:

Tunnel

Tunnel, in this application, is the usage of localtunnel CLI. This will get our localhost server and expose this to a secure proxy on the internet. :

npm install -g localtunnel

Before run localtunnel, keep in mind that you will need use a fixed proxy, or in other words, the same domain registered in BotFather

And run, as a service, a child processes or a another background command:

lt --port <ACCESS_PORT> --subdomain <SUBDOMAIN>

If you like nginx, you can use a reverse proxy and use:

lt --port 80 --subdomain <SUBDOMAIN>

Info

For more information on all the things you can do with Feathers visit docs.feathersjs.com.

Changelog

0.1.14

0.1.13

0.1.12

0.1.11

0.1.1

0.1.0

License

CC BY-SA 4.0

Licensed under the CC-BY-SA license.