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

timbot2

v0.2.3

Published

Timbot2 makes it easy to create a bot with custom actions for your slack channel.

Downloads

11

Readme

timbot2

Timbot2 makes it easy to create a bot with custom actions for your slack channel. Timbot2 uses botkit. It should restart on it's own if it disconnects. Look at botkit's slack readme to find information about what channels timbot2 custom actions should be set to and understand controller actions.

Installation

  • Install timbot2 globally.
npm install timbot2 --global
  • Create a custom integration bot at slack.
  • Fill out the settings and save the api token.
  • Save the token in an .env file saved in the directory timbot2 will run.
  • Invite your bot to your slack channel.

.env file

SLACK_TOKEN=token

Create a custom command

Creating custom actions for your bot is very easy. Although it's possible to do this without using typescript, it's much easier with it.

  • Create a new npm project (npm init)
  • Save timbot2 (npm install --save timbot2)
  • Save to dev typescript (npm install --save-dev typescript)
  • Create your custom command using typescript
  • Custom command class name must be the same as its filename.
  • Compile (tsc)
  • run (timbot2)

Example - Pizza (Pizza.ts)

import {BotListener} from "timbot2/lib/BotListener";

export class Pizza extends BotListener {
  name = "pizza"; //required
  desc = "Yum, pizza"; // required

  // not required; defaults to false
  // if set true, doesn't show up in help
  hidden = true;

  // not required, defaults to true
  // if set to false, does not run
  // in the custom listener
  // possibly use it in combo with env variable.
  active = true;

  // not extended from BotListener variable
  channels = ['direct_message','direct_mention','mention','ambient'];

  // required function
  start() {

    var Pizza = this;
    Pizza.controller.hears('pizza', this.channels, function(bot,message) {

      // reply
      Pizza.reply(bot, message, "pizza? I want pizza");
      // reply as code
      Pizza.replyCode(bot, message, "pizza" I want pizza");


    // to use reply
    });
  }
}

Example - package.json

{
  "name": "timbot2-custom-examples",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "compile": "tsc"
  },
  "author": "tmitim",
  "license": "MIT",
  "dependencies": {
    "timbot2": "^0.1.2
  },
  "devDependencies": {
    "typescript": "^2.1.5"
  }
}

Example tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false
    }
}

Note

  • Due to the botkit, timbot2 will only take action to the first message it "hears". So if two custom actions overlap, only the first action can be heard.

Dependencies

  • botkit: Building blocks for Building Bots
  • dotenv: Loads environment variables from .env file

Dev Dependencies

  • @types/node: TypeScript definitions for Node.js
  • typescript: TypeScript is a language for application scale JavaScript development

License

MIT