0.0.58 • Published 24 days ago

@sagi.io/workers-slack v0.0.58

Weekly downloads
-
License
MIT
Repository
github
Last release
24 days ago

workers-slack

@sagi.io/workers-slack allows you to use Slack's Web API within Cloudflare Workers.

⭐ We use it at OpenSay to access Slack's REST API through Cloudflare Workers.

Here is a blog post that explains why I built it.

CircleCI MIT License version

Installation

$ npm i @sagi.io/workers-slack

Cloudflare Workers Usage

If you use Cloudflare's Wrangler you must set the node_compat flag in your wrangler.toml - the reason for this is that this library is built both for Cloudflare Workers and Node.js (for which we need globals).

Initialize SlackREST:

// Without token:
const SlackREST = require('@sagi.io/workers-slack')
const SlackAPI = new SlackREST()

// With token:
const botAccessToken = process.env.SLACK_BOT_ACCESS_TOKEN;
const SlackREST = require('@sagi.io/workers-slack')
const SlackAPI = new SlackREST({ botAccessToken })

You can then use supported Slack methods. For instance, here's how to use the chat.postMessage method:

// SlackREST was initialized with a token
const formData = { channel: 'general', text: 'hello world'}

// SlackREST wasn't initialized with a token
const botAccessToken = process.env.SLACK_BOT_ACCESS_TOKEN;
const formData = { token: botAcccessToken, channel: 'general', text: 'hello world' }

const result = await SlackREST.chat.postMessage(formData)

Verifying requests from Slack

More information here.

The SlackREST.helpers.verifyRequestSignature method returns true when a signature from Slack is verified. Otherwise it throws an error.

const SlackREST = require('@sagi.io/workers-slack')
const SlackAPI = new SlackREST()

const signingSecret = process.env.SLACK_SIGNING_SECRET
const isVerifiedRequest = await SlackAPI.helpers.verifyRequestSignature(request, signingSecret)
0.0.57

24 days ago

0.0.58

24 days ago

0.0.55

1 year ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.54

1 year ago

0.0.50

2 years ago

0.0.46

2 years ago

0.0.48

2 years ago

0.0.42

2 years ago

0.0.44

2 years ago

0.0.40

2 years ago

0.0.37

3 years ago

0.0.36

3 years ago

0.0.34

3 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.29

4 years ago