GithubHelp home page GithubHelp logo

thinhit / slack-bot-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mishk0/slack-bot-api

0.0 2.0 0.0 77 KB

Simple way to control your Slack Bot

License: MIT License

JavaScript 100.00%

slack-bot-api's Introduction

SlackBots.js

license Build Status npm

This is Node.js library for easy operation with Slack API.

It also exposes all opportunities of Slack's Real Time Messaging API.

Events

  • start - event fired, when Real Time Messaging API is started (via websocket),
  • message - event fired, when something happens in Slack. Description of all events here.

Methods

  • getChannels (return: promise) - returns a list of all channels in the team,
  • getUsers (return: promise) - returns a list of all users in the team,
  • getUser (return: promise) - gets user by name,
  • getChannel (return: promise) - gets channel by name,
  • getChatId (return: promise) - it returns or opens and returns a direct message channel ID,
  • postMessage - posts a message to channel by ID,
  • postMessageToChannel - posts a message to channel by name,
  • postMessageToUser - posts a direct message by user name.

Usage

var SlackBot = require('slackbots');

// create a bot
var bot = new SlackBot({
    token: 'xoxb-012345678-ABC1DFG2HIJ3', // Add a bot https://my.slack.com/services/new/bot and put the token 
    name: 'My Bot'
});

bot.on('start', function() {
    // more information about additional params https://api.slack.com/methods/chat.postMessage
    var params = {
        icon_emoji: ':cat:'
    };
    
    bot.postMessageToChannel('general', 'meow!', params);
    bot.postMessageToUser('username', 'meow!', params);
});

PROFIT!

/**
 * @param {object} data
 */
bot.on('message', function(data) {
    // all ingoing events https://api.slack.com/rtm
    console.log(data);
});

slack-bot-api's People

Contributors

mishk0 avatar thesisb avatar

Watchers

James Cloos avatar Thinh Nguyen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.