npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@menome/botframework

v3.2.2

Published

Common functionality for building bots (containerized microservices with a specific set of API calls) for integration with the Menome stack

Downloads

6

Readme

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.