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

@broid/kit

v1.1.0

Published

Bot framework supported all messaging plateforms and middlewares.

Downloads

55

Readme

npm node bithound bithoundscore nsp-checked

Broid Kit

Broid Kit aims to ease the creation of bots communicating through messaging platforms. Broid Kit is powered by Broid Integrations which allows you to leverage the largest collection of messaging channels integrated in a given framework.

Connect your App to Multiple Messaging Channels with the W3C Open standards.

gitter join-slack

Quick Example

Note: Options for the integration examples can be found on the Discord, Messenger, and Slack documentation respectively.


const Bot = require("@broid/kit");
const BroidDiscord = require("@broid/discord");
const BroidMessenger = require("@broid/messenger");
const BroidSlack = require("@broid/slack");

const bot = new Bot({
  logLevel: "info",
  http: {
    host: "0.0.0.0",
    port: 8080,
  }
});

bot.use(new BroidDiscord({...options}));
bot.use(new BroidMessenger({...options}));
bot.use(new BroidSlack({...options}));

// Listening for public starting by regex match for `hello`
bot.hear("hello.*", "Group")
  .subscribe((data) => {
    console.log("Data:", JSON.stringify(data, null, 2));

    // Reply to the message
    bot.sendText("Hi, How are you?", data.message);
  });

Broid-Kit can also be used with your existing Express setup.


const Bot = require("@broid/kit");
const BroidDiscord = require("@broid/discord");
const BroidMessenger = require("@broid/messenger");
const BroidSlack = require("@broid/slack");
const express = require("express");

const bot = new Bot({
  logLevel: "info"
});

bot.use(new BroidDiscord({...options}));
bot.use(new BroidMessenger({...options}));
bot.use(new BroidSlack({...options}));

// Setup express
const app = express();
app.use("/", bot.getRouter());
app.listen(8080);

// Listening for public starting by regex match for `hello`
bot.hear("hello.*", "Group")
  .subscribe((data) => {
    console.log("Data:", JSON.stringify(data, null, 2));

    // Reply to the message
    bot.sendText("Hi, How are you?", data.message);
  });

Documentation

Receive all group messages

bot.on("Group")
  .subscribe((data) => {
    console.log("Data:", JSON.stringify(data, null, 2));

    // Reply to the message
    bot.sendText("i am listening all messages", data.message);
  });

Receive all private messages

bot.on("Person")
  .subscribe((data) => {
    console.log("Data:", JSON.stringify(data, null, 2));

    // Reply to the message
    bot.sendText("i am listening all messages", data.message);
  });

Receive all

Because Broid Kit is built with Observables, you can subscribe to multiple sources.

const Observable = require("rxjs").Observable;

Observable.merge(bot.on("Group"), bot.on("Person"))
  .subscribe((data) => {
    console.log("Data:", JSON.stringify(data, null, 2));

    // Reply to the message
    bot.sendText("i am listening all messages", data.message);
  });

Matching patterns and keywords

bot.hears(["keyword", "hello.*"], "Group")
  .subscribe(data => {
    console.log("Data:", JSON.stringify(data, null, 2));
  });

Node callback is supported

bot.hear("hello.*", "Group", (data, error) => {
  console.log("Data:", JSON.stringify(data, null, 2));
});
bot.hears(["keyword", "hello.*"], "Group", (data, error) => {
  console.log("Data:", JSON.stringify(data, null, 2));
});

Send a simple message

bot.sendText("Hello world.", data.message);

Send a video or image message

bot.sendImage("http://url-of-media", data.message, optionalMeta);

// OR

bot.sendVideo("http://url-of-media", data.message, optionalMeta);

optionalMeta is an object of optional information for the media. It should like:

{
  "content": "description of the meta",
  "title": "title for the media"
}

Middleware

Broid kit supports middleware to allow you to preprocess received or sent messages.

Example of Middleware preprocessing

class MyMiddleware {
  constructor() {}

  serviceName() {
    return "MyMiddleware";
  }

  incoming(bot, message) {
    // the return value can be an Promise<object>, Observable<object> or null
    return "Hello world!";
  }

  outgoing(bot, message) {
    // the return value can be an Promise<object>, Observable<object> or null
    // The object.content field will be use to update the text of the message sent.
    return "Good bye world!";
  }
}

This middleware can be used like so:

bot.use(new MyMiddleware());

WebHooks

Broid Kit provide an http server and creates a default webhook route when the integration requires it. By default, the webhook path follows the naming convention: webhook/<integration>, integration is the name provide by the getServiceName method.

In case of @broid/skype the webhook route will be /webhook/skype.

Contribute

See CONTRIBUTE.md.

License