Skip to content

Node.js bot and personal assistants platform. Boilerplate, start point, tools, best practices for building bots and personal assistants.

Notifications You must be signed in to change notification settings

evilai/nodejs-bot-platform

Repository files navigation

Node.js Bot Platform

This is a Node.js platform for bots (boilerplate and start point). Implemented on top of Express, which is used only for routing, so it's easily can be changed. Platform in this case is a boilerplate, set of tools, architecture and best practices for bot building.

What's implemented.

Keys (important)

Google Cloud

Be sure that you replaced keys in /keys/ folder. To download json with keys:

  1. Go to Google Console API manager and check credentials.
  2. Click on the button Create credentials -> Service Account Key -> JSON.
  3. Download generated file, rename it to google.json and replace /keys/google.json.
  4. Don't forget to enable APIs (if you use it, of course):
    • Datastore
    • Natural Language

Other keys

Please, replace app.yaml and app-dev.yaml files and provide listed keys. If you use different environments (live/staging/dev), don't forget to specify different keys. Right now there are only two environments: development and production.

Example of app.yaml file:

runtime: custom
vm: true

env_variables:
  LOGGING_LEVEL: 'debug'
  APP_WIT_TOKEN: 'yourkeyhere'
  APP_WIT_VERSION: '20161008'
  GOOGLE_PROJECT_ID: 'youridhere'
  FACEBOOK_PAGE_TOKEN: 'yourtokenhere'
  NEW_RELIC_APP_NAME: 'youappname'
  NEW_RELIC_LICENSE: 'yourkey'

Example of the app-dev.yaml file:

runtime: custom
vm: true

env_variables:
  LOGGING_LEVEL: 'silly'
  APP_WIT_TOKEN: 'yourkeyhere'
  APP_WIT_VERSION: '20161008'
  MEMCACHE_PORT_11211_TCP_ADDR: 'localhost'
  MEMCACHE_PORT_11211_TCP_PORT: '11211'
  GOOGLE_PROJECT_ID: 'youridhere'
  FACEBOOK_PAGE_TOKEN: 'yourtokenhere'
  NEW_RELIC_APP_NAME: 'youappname'
  NEW_RELIC_LICENSE: 'yourkey' 

It's almost the same, but logging level is different and you need to provide memcached host and port. In case of app.yaml (for production) it will be provided by Google App Engine automatically.

Build

For building I use webpack. Please, notice that I have aliases for common libraries and files, that I use:

  • skill-cluster (pretty self explanatory, will discuss later)
  • config (please, keep only global configuration for the whole platform)
  • logger (based on Winston)

You can find configuration at /build/index.js.

How to build

  • npm run build:dev - build for development.
  • npm run build:dev:watch – build for development in watch mode.

Start

Package.json scripts

  • npm run start – run production environment with keys from app.yaml.
  • npm run start:dev – run development environment with keys from app-dev.yaml.

Shell scripts

All shell scripts are used by package.json scripts, so you don't need to run it explicitly.

  • /tools/start/prod.sh – read variables from app.yaml and starting builded bot in /dist/bot.js.
  • /tools/start/dev.sh – read variables from app-dev.yaml and starting builded bot in /dist/bot.js.

Deployment

Node.js Bot Platform right now is easily deployable to Google App Engine.

Architecture

Please, check code and folders. I'll try to add README in all folders and leave as much comments in the code as possible.

File system

  • The major folder is /src/bot. There you should put all skills clusters for all IM Platforms.
  • In folder /src/bot/skills/clusters you should put only reusable (between different platforms) skills and skills clusters.
  • In folder /src/bot/platforms/ you should put unique, not reusable skills and clusters.

Code

Please, check comments inside files. I use Express.

index.js

In the index.js file look at yourBotMessengerRouter and buildRoute functions, that add new route to Express Router. This route should be used by webhooks (like FB Messenger) or device API.

  • '/messenger/yourbot' – is a url, that you need to specify in your messenger webhooks. For example https://yourbot.app.com/messenger/yourbot.
  • buildRoute – just add provided routes to the Express Router.
  • yourBotMessengerRouter – is the most important part. There you can add or remove different services, that you want to use (for example, Google Storage, Memcached, Wit.ai and others) in your skills. Also you specify the initial Skills Cluster:
/bot/platforms/messenger/bot-name/router-builder.js

Check comments inside files. In this file you should:

  • add routes for web hooks;
  • set up all services that can be used in skills;
  • initialize request context, that can be passed between skills;
  • and finally run initial Skills Cluster.

Releases

No releases published

Packages

No packages published