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

role-model

v2.0.0

Published

Robot on LeanEngine

Downloads

29

Readme

Build Status

RoLE model

What's this?

RoLE stands for Robot on LeanEngine. It's a library for writing chat robot hosted on LeanEngine. LeanEngine is a service provided by LeanCloud.

Instructions

RoLE is available on NPM. Add "role-model": "^0.0.9" to your package.json.

The package only exports one method createRobotApp():

const role = require('role-model');

const app = role.createRobotApp({
  chatService: 'bearychat',
  chatServiceOptions: {
    team: process.env.BEARYCHAT_TEAM,
    token: process.env.BEARYCHAT_TOKEN
  }
});

As of this writing, BearyChat and Zulip are the only supported service, but it is very easy to add support to other services (look at lib\zulip.js for an example). Please contribute. In the above example, the credentials were read from environment variables which can be set on the LeanCloud web console.

The returned object has three properties:

  • expressApp - an Express app instance, which you can use to add additional routes and middleware.
  • leanEngine - a LeanEngine SDK instance that you would otherwise get from require('leanengine'). This is provided just in case you need LeanCloud functionalities such as data storage.
  • robot - this is the object you would use to define the behavior of your robot.

The robot is programmed by defining predicates to match incoming messages and their handlers.

You can use a list of keywords:

app.robot.addHandler(['ping'],
    context => context.respond('pong'));

If the incoming message has all the keywords, the handler will be executed.

Or you can use a regular expression:

app.robot.addHandler(/ping/,
    context => context.respond('pong'));

Or to be most flexible, just a plain function:

app.robot.addHandler((msg) => msg === "ping",
    context => context.respond('pong'));

At the end, call

app.run()

This needs to be the last line in your main program, because it's blocking (calls expressApp.listen()).

Now deploy your project to LeanCloud, configure your web hosting domain name, and add a robot of type "Hubot" to your BearyChat team. You should be able to receive responses from your new bot.

Make sure you use Node 4+, because RoLE uses some ES6 features. So add the following to your package.json:

  "engines": {
    "node": ">=4.x"
  }