How Slack does SDKs

Slack's various APIs area a mix of a lot of tech: traditional REST APIs, realtime APIs, webhooks, and more. To help deal with it, they have an awesome Node SDK that hides away most of the complexity!

const { IncomingWebhook } = require('@slack/client');
const url = process.env.SLACK_WEBHOOK_URL;
const webhook = new IncomingWebhook(url);

// Send simple text to the webhook channel
webhook.send('Hello there', function(err, res) {
    if (err) {
        console.log('Error:', err);
    } else {
        console.log('Message sent: ', res);
    }
});

You might notice something strange about Slack's API: each endpoint takes a POST (so no GETs or PUTs or anything like that), and is named more like a method than a URL.

Between the structure and the SDKs, using Slack's API is more like calling a local function than an API. It's comfortable to use, and you can quickly build some awesome stuff!