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

xmpp-command-bot

v0.8.0

Published

An XMPP chat bot for running local commands

Downloads

17

Readme

xmpp-command-bot

An XMPP bot which takes messages from a chat room or a prescribed set of users and runs commands on the local server.

Build status: Build Status Coverage Status Dependency Status devDependency Status Donate to help support development

Setup

Copy config.example.js to config.js and modify as required.

XMPP Connection

An example XMPP configuration object is as follows:

{
    xmpp: {
        connection: {
            jid: 'bot@localhost',
            password: 'mysecretpassword'
        },
        muc: {
            room: 'chat',
            server: 'localhost',
            nick: 'commander',
            password: 'letmein',
         /* roles: [ 'moderator', 'participant', 'visitor' ] */
        },
        admins: [
            'fail@localhost',
            /lloyd@[^localhost]/,
            function(stanza, context) {
                return true
            }
        ]
    }
}

The connection key contains details for the bot to connect to the XMPP server. These values are passed directly to the constructor of the node-xmpp-client. For more connection choices please see the linked manual.

Setting allowed users

Using the admin key within xmpp section of the configuration to set what XMPP JIDs can make requests to the chat bot. There are three methods by which you can define allowed JIDs:

  • bare JID match
  • regular expression match
  • function match

The admin matching methods are called in order, if any of the methods provide a match then the command will be accepted.

Bare JID match

The bare JID of the sender is compared to the provided values.

Regular Expression match

The bare JID of the sender is compared to the provided value using a regular expression match.

Function match

The original stanza is passed to your provided function, return true or false in order tell the bot whether to accept this request.

Connecting to a chat room

By providing details under the muc key. The minimum keys are 'room', 'server', and 'nick' (nickname). If the room is password protected then adding the password to the 'password' key will allo you to connect. You can control which roles can send commands by setting the 'roles' key.

In MUC rooms the bot can be talked as follows:

bot-nick: do_stuff

Adding commands

{
    commands: {
        'cat': {
            command: 'cat',
            reply: true,
            summary: 'Cat a file',
            description: 'Return the contents of a file'
            arguments: /^[a-z0-9]*$/i,
            options: { timeout: 2000 }
        }
    }
}

Using the commands key of the bot configuration allows you to set up commands. It takes the form of a keyed object with the key being the command identifier.

Command (required)

The command to be run

Reply

If set to false then the command is run without any response returned.

Summary (required)

A summary of the command being run - included in the help response.

Description

A longer description of the command being run.

Arguments

If arguments are accepted for the command then they can be expected here:

  • false: Arguments aren't accepted
  • true: Blanket accept arguments - be very careful using this
  • regex: Match arguments using a regular expression
  • function: Passed the arguments object. Return false for 'failed to match' and return the processed arguments if provided arguments are ok

Options

Upstart script

There is an upstart script located in contrib/xmpp-command-bot.conf. Copy this to /etc/init/ then run:

sudo service xmpp-command-bot start

The script is set up to run out of /usr/share/xmpp-command-bot and as the user xmpp.

Testing

npm test

Debugging

DEBUG=* node index

Various values for debug can be used, currently the following are supported:

  • xmpp
  • commander

Licence

MIT