Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slack-basebot

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slack-basebot

BaseBot for Slack

  • 2.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Slack BaseBot

Install

npm install slack-basebot --save

Simple Example

"use strict";
const BaseBot = require('slack-basebot');
const MyBot = new BaseBot('xob-slacktoken','MyBotName', {debug:true});

MyBot.onDirectQuestion(/please help me/i, msg => {
    //== Will trigger when someone says `MyBotName please help me` or with a mention like `please help me @MyBotName`;

    //== We can react with an emoji
    msg.react('heart');

    //== We can auto-randomly react with an emoji
    msg.react(['heart','black_heart','green_heart']);

    //== And/or reply (as often as we like)
    msg.reply(`What can I help you with ${msg.user.name}?`);

    //== Randomize the output with an array:
    msg.reply(['Sometimes I say foo','That other time I will say bar']);

    //== Furthermore we have some more user, channel and message information
    console.info('@User:', msg.user);
    console.info('#Channel', msg.channel);
    console.info('Is this a DM?', msg.isDirect);
    console.info('Full message ', msg.message);
    console.info('@user said: ', msg.text);
})

MyBot.onPhrase(/squirl/gi, msg => {
    //== This will trigger everytime anyone says something containing squirl.
    msg.react('squirrel');

    //== Pretend we are typing for 3 seconds
    msg.typing(3 * 1000).then(() => {
        msg.reply('I took me 3 seconds to write this.');
    });
});

MyBot.setHelpText(() =>  `Hi I'm ${MyBot.tag}. I can do stuff for you.`);
MyBot.always(msg => console.info('Triggered on every incoming message'));
MyBot.onNothing(msg => console.info('Triggered on DirectQuestion/mention when no rules are matched.'));

//== Any sub-event can be listened on (see https://api.slack.com/events/message)
MyBot.on('channel_leave', event => console.info('Event happened', event));

//== On ChannelJoin of this bot
this.onChannelJoin(event => this.sendMessage(`Thanks <@${event.inviter}> for inviting me to <#${event.channel}>. How can I help you?`, event.channel));

Inheritance Example

"use strict";
const BaseBot = require('slack-basebot');

class MyBot extends BaseBot {
    constructor() {
        super('xob-slacktoken','MyBotName', {debug:true});
        this.start();
    }

    start() {
        this.onDirectQuestion(/please help me/i, msg => { /* Same as example above */})
        this.onPhrase(/squirl/gi, msg => { /* Same as example above */});
        this.setHelpText(() =>  `Hi I'm ${MyBot.tag}. I can do stuff for you.`);
        this.always(msg => console.info('Triggered on every incoming message'));
        this.onNothing(msg => console.info('Triggered on DirectQuestion/mention when no rules are matched.'));
    }
}

FAQs

Package last updated on 07 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc