3.2.2 • Published 2 years ago

@menome/botframework v3.2.2

Weekly downloads
-
License
Commercial
Repository
github
Last release
2 years ago

Menome Bot Framework

View the full API Doc here

View an example bot here

View the schemas here

This package contains a common framework for all bots that integrate with theLink or the Menome stack.

Bots commonly have the following functionality:

  • Can Connect to RabbitMQ and send + receive messages with routing keys.
  • Be able to connect to and run queries on the Neo4j graph.
  • Can describe themselves, their functionality, and their state via API calls.
    • eg. A harvester bot should be able to tell us, via REST calls, that it has a /sync endpoint, or that performing a GET on /status gives the progress of the current sync job.

Usage

To use the framework, just follow these steps:

  1. Import the framework
  2. Instantiate a bot. (Use var bot = new Bot({config, configSchema})) (See Below)
  3. Configure Swagger Endpoints (See Below)
  4. Start the bot by calling bot.start()
  5. Set the bot's initial state with bot.changeState({state: "idle"})

For a complete list of functions that you can utilize, see the API Docs

Configuration

Configuration is specified in the following structure: (Default values shown)

{
  "name": "SQL Harvester",
  "desc": "Harvests from something",
  "nickname": "World Database Harvester",
  "urlprefix": "/",
  "logging": true,
  "port": 80,
  "rabbit": {
    "enable": false,
    "url": "amqp://rabbitmq:rabbitmq@rabbit:5672?heartbeat=3600",
    "routingKey": "syncevents.harvester.updates.example",
    "exchange": "syncevents",
    "exchangeType": "topic"
  },
  "neo4j": {
    "enable": false,
    "url": "bolt://localhost",
    "user": "neo4j",
    "pass": "password"
  },
  "ssl": {
    "enable": false,
    "certpath": "/srv/app/ssl/cert.pem",
    "keypath": "/srv/app/ssl/key.pem",
    "port": 443
  }
}

Configuration is handled through Mozilla Convict. For more information on our baseline config structure, see the config schema.

When creating a new bot, call the constructor and supply an object like the one above as a config parameter.

Additionally, you can specify a configSchema. This will be merged in with the default bot schema for when you want to supply your own configuration parameters.

For example, this would set up a new bot with some custom config parameters.

var bot = require('@menome/botframework')

var config = {
  name: "JSON Placeholder Bot",
  desc: "Harvests data from JSON placeholder.",
  nickname: "Jerry",
  // (Add some additional config params for rabbit, neo4j, ports in use, etc)
}

var configSchema = {
  url: {
    doc: "The URL of the REST Endpoint we're grabbing",
    format: "url",
    default: "https://jsonplaceholder.typicode.com",
    env: "API_URL"
  }
}

var bot = new Bot({ config, configSchema });

Register Web Endpoints

The Bot Framework is built to be OpenAPI compliant. Navigate to the [bot address]/docs to view the bot's OpenAPI spec through the swagger UI

To register additional endpoints, you must call bot.registerPaths(paths, controllersDir);.

An easy way to sed this up is to have a subdirectory called 'controllers' in which you put your controllers and their swagger stubs. A file in this directory might look like this:

// controllertest.js
module.exports.swaggerDef = {
  "/ping": {
    "x-swagger-router-controller": "controllertest",
    "get": {
      "tags": [
        "JSONPlaceholder"
      ],
      "responses": {
        "200": { "description": "Success" },
        "default": { "description": "Error" }
      }
    }
  }
}

module.exports.get = function(req,res) {
  return res.send({message: "Pong!"});
}

To load these and register them with the bot, you can do something like this:

var path = require('path');

bot.registerControllers(path.join(__dirname,"./controllers"));
bot.start())

For more information on OpenAPI and Swagger, read their documentation here.

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago

2.3.0

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.14

6 years ago

2.1.13

6 years ago

2.1.12

6 years ago

2.1.11

6 years ago

2.1.10

6 years ago

2.1.9

6 years ago

2.1.8

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago