npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@weweb/backend-slack

v0.2.3

Published

Slack integration for WeWeb backend services

Downloads

114

Readme

WeWeb Slack Integration

A WeWeb backend integration for Slack's API, providing access to messaging, channels, users, and other Slack features within WeWeb backend workflows. This integration uses the official @slack/web-api package for robust and type-safe interactions with Slack's API.

Features

  • Simple integration with Slack's API
  • Send messages to channels and users
  • Create and manage channels
  • Invite users to channels
  • Upload files to Slack
  • Search messages
  • Access user and workspace information

Installation

This package is designed to work with the WeWeb Supabase Backend Builder and Deno.

import { serve } from '@weweb/backend-core';
import { createSlackIntegration } from '@weweb/backend-slack';

Usage

Basic Setup

import type { BackendConfig } from '@weweb/backend-core';
import { serve } from '@weweb/backend-core';
import Slack from '@weweb/backend-slack';

// Define your backend configuration
const config: BackendConfig = {
  workflows: [
    // Your workflows here
  ],
  integrations: [
    // Use the default Slack integration
    Slack,
    // Or add other integrations
  ],
  production: false,
};

// Start the server
const server = serve(config);

Custom Configuration

You can customize the Slack client by using the createSlackIntegration function:

import { createSlackIntegration } from '@weweb/backend-slack';

// Create a custom Slack integration
const customSlack = createSlackIntegration({
  botToken: 'xoxb-your-bot-token', // Override environment variable
  userToken: 'xoxp-your-user-token', // Optional
  apiUrl: 'https://your-custom-endpoint.com', // Optional
});

If not specified, the integration will use the following environment variables:

  • SLACK_BOT_TOKEN - Your Slack Bot User OAuth Token (xoxb-...)
  • SLACK_USER_TOKEN - Your Slack User OAuth Token (xoxp-...)
  • SLACK_API_URL - Custom API endpoint URL (optional, defaults to https://slack.com/api)

Available Methods

Post Message

Send messages to channels or users.

// Example workflow action
const config = {
  type: 'action',
  id: 'send_slack_message',
  actionId: 'slack.post_message',
  inputMapping: [
    {
      channel: 'general',
      text: 'Hello from WeWeb! 👋',
      mrkdwn: true
    }
  ]
};

Create Channel

Create a new public channel in a workspace.

// Example workflow action
const config = {
  type: 'action',
  id: 'create_slack_channel',
  actionId: 'slack.create_channel',
  inputMapping: [
    {
      name: 'project-updates',
      validate: true
    }
  ]
};

Invite to Channel

Invite users to a channel.

// Example workflow action
const config = {
  type: 'action',
  id: 'invite_users',
  actionId: 'slack.invite_to_channel',
  inputMapping: [
    {
      channel: 'project-updates',
      users: 'U0123456789,U9876543210'
    }
  ]
};

List Channels

Get a list of all channels in the workspace.

// Example workflow action
const config = {
  type: 'action',
  id: 'get_channels',
  actionId: 'slack.list_channels',
  inputMapping: [
    {
      exclude_archived: true,
      limit: 100
    }
  ]
};

List Users

Get a list of all users in the workspace.

// Example workflow action
const config = {
  type: 'action',
  id: 'get_users',
  actionId: 'slack.list_users',
  inputMapping: [
    {
      limit: 100
    }
  ]
};

Upload File

Upload a file to Slack.

// Example workflow action
const config = {
  type: 'action',
  id: 'upload_file',
  actionId: 'slack.upload_file',
  inputMapping: [
    {
      file: '$body.fileContent', // Base64 encoded file
      filename: 'report.pdf',
      title: 'Monthly Report',
      channels: 'general,reports'
    }
  ]
};

Example: Complete Notification Application

import type { BackendConfig } from '@weweb/backend-core';
import { serve } from '@weweb/backend-core';
import Slack from '@weweb/backend-slack';

const config: BackendConfig = {
  workflows: [
    {
      path: '/notify',
      methods: ['POST'],
      security: {
        accessRule: 'public',
      },
      inputsValidation: {
        body: {
          type: 'object',
          properties: {
            channel: { type: 'string' },
            title: { type: 'string' },
            message: { type: 'string' },
            importance: { type: 'string', enum: ['low', 'medium', 'high'] }
          },
          required: ['channel', 'title', 'message'],
        },
      },
      workflow: [
        {
          type: 'action',
          id: 'send_notification',
          actionId: 'slack.post_message',
          inputMapping: [
            {
              channel: '$body.channel',
              blocks: [
                {
                  type: 'header',
                  text: {
                    type: 'plain_text',
                    text: '$body.title'
                  }
                },
                {
                  type: 'section',
                  text: {
                    type: 'mrkdwn',
                    text: '$body.message'
                  }
                },
                {
                  type: 'context',
                  elements: [
                    {
                      type: 'mrkdwn',
                      text: '*Importance:* $body.importance'
                    }
                  ]
                }
              ]
            },
          ],
        },
      ],
    },
  ],
  integrations: [Slack],
  production: false,
};

console.log('Starting Slack notification server on http://localhost:8000/notify');
serve(config);

Authentication

This integration uses the official Slack Web API client and requires Slack API tokens to function:

  1. Bot Token (xoxb-...): Used for most API calls. This token is obtained by creating a Slack App, adding Bot Token Scopes, and installing the app to your workspace.

  2. User Token (xoxp-...): Required for some user-level actions like search_messages. This token is obtained by adding User Token Scopes to your Slack App.

For full details on obtaining these tokens, see Slack's API documentation.

Required Scopes

Depending on which methods you use, your Slack app will need different OAuth scopes:

Bot Token Scopes

  • chat:write - For posting messages
  • channels:read - For listing channels
  • channels:write - For creating channels
  • users:read - For listing users
  • reactions:write - For adding reactions
  • files:write - For uploading files

User Token Scopes

  • search:read - For searching messages

Make sure to add the required scopes to your Slack app based on the functionality you need.