Wondering what’s next for npm?Check out our public roadmap! »

    slack-wrapi

    1.0.2 • Public • Published

    Slack Web API

    The simplest library for Slack Web API.

    Call Slack Web API endpoints just like functions

    NPM version Build Status Coverage Status

    Installation

    Install via npm

    npm install slack-wrapi --save

    Usage

    Create a Slack client with the API token.

    const slackWrapi = require('slack-wrapi');
     
    const slack = new slackWrapi(SLACK_API_TOKEN);
     
    // Now you are ready to make API calls to Slack.

    Function names match with Slack API endpoints (methods) as per the documentation.

    Just provide parameters and a callback or get back a Promise.

    API calls follow this syntax:

    slack.apigroup.action(queryString, callback);

    • queryString - (as required) API method parameters as key-value pairs.

    If no callback is provided, the function returns a Promise object.

    Post a message with callback:

    // ES5 Syntax with callback
    slack.chat.postMessage({
        "channel": "#general",
        "text": "Hello World!"
      },
      function(err, res) {
        if (!err) {
          console.log('Message posted: ', res.ts);  
        }
      }
    )

    Post a message. Get back a Promise:

    // ES2015 Promise
    slack.chat.postMessage({
      "channel": "#general",
      "text": "Hello World!"
    })
    .then((res) => {
      console.log('Message posted: ', res.ts);  
    })
    .catch(console.error);

    Post a message via async/await:

    // ES2017 async/await
    (async () => {
      try {
        const res = await slack.chat.postMessage({
          "channel": "#general",
          "text": "Hello World!"
        });
     
        console.log('Message posted: ', res.ts);  
      }
      catch(err) {
        console.error(err);
      }
    })();

    Call any Slack Web API methods with the client object.

    Examples

    Lists custom emojis for a team.

    slack.emoji.list(function(err, data) {
      if (!err) {
        console.log(data);
      }
    });

    Lists all channels in a Slack team.

    slack.channels.list({exclude_archived:1}, function(err, data) {
      if (!err) {
        console.log(data);
      }
    });

    Gets information about a private group.

    slack.groups.info({channel:"G1234567890"}, function(err, data) {
      if (!err) {
        console.log(data);
      }
    });

    Adds a reaction to an item.

    slack.reactions.add({
        name: "thumbsup",
        file: "F1234567890",
        file_comment: "Fc1234567890",
        channel:"G1234567890",
        timestamp: "1234567890.123456"
      },
      function(err, data) {
        if (!err) {
          console.log(data);
        }
      }
    );

    Gets information about a user.

    slack.users.info({user: "U1234567890"}, function(err, data) {
      if (!err) {
        console.log(data);
      }
    });

    Post chat messages to Slack.

    slack.chat.postMessage({
        "channel": "#general",
        "text": "Hello <@u12345678|world>!",
        "username": "Wrapi Bot",
        "as_user": false,
        "parse": "full",
        "link_names": 1,
        "attachments": [{"pretext": "pre-hello", "text": "text-world"}],
        "unfurl_links": true,
        "unfurl_media": false
      },
      function(err, data) {
        if (!err) {
          console.log(data);
        }
      }
    )

    Check user's current Do Not Disturb settings.

    slack.dnd.info({
        "user": "U1234"
      },
      function(err, data) {
        if (!err) {
          console.log(data);
        }
      }
    )

    API Methods

    api

    apps.permissions

    apps.permissions.resources

    apps.permissions.scopes

    apps.permissions.users

    apps

    auth

    bots

    channels

    chat

    conversations

    dialog

    dnd

    emoji

    files.comments

    files

    groups

    im

    migration

    mpim

    oauth

    pins

    reactions

    reminders

    rtm

    search

    stars

    team

    team.profile

    usergroups

    usergroups.users

    users

    users.profile

    License

    MIT

    Install

    npm i slack-wrapi

    DownloadsWeekly Downloads

    8

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    28.9 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar