All Projects → raycharius → Slack Block Builder

raycharius / Slack Block Builder

Licence: mit
Lightweight, no-dependency JavaScript library for creating Slack Block Kit UIs, with a builder syntax, inspired by SwiftUI.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Slack Block Builder

Slack Machine
A sexy, simple, yet powerful and extendable Slack bot
Stars: ✭ 91 (-29.46%)
Mutual labels:  bot-framework, slack-bot, slackbot, slack-api, slack
Awesome Bots
The most awesome list about bots ⭐️🤖
Stars: ✭ 2,864 (+2120.16%)
Mutual labels:  bots, bot-framework, slack-bot, slackbot, slack
Slacker
Slack Bot Framework
Stars: ✭ 495 (+283.72%)
Mutual labels:  bot-framework, slack-bot, slackbot, slack-api, slack
dienstplan
Slack bot app for duty rotations
Stars: ✭ 14 (-89.15%)
Mutual labels:  slack, slackbot, slack-bot, slack-api
Jbot
Make Slack and Facebook Bots in Java.
Stars: ✭ 1,148 (+789.92%)
Mutual labels:  bot-framework, slack-bot, slackbot, slack
Slack Ruby Client
A Ruby and command-line client for the Slack Web, Real Time Messaging and Event APIs.
Stars: ✭ 957 (+641.86%)
Mutual labels:  slack-bot, slackbot, slack-api, slack
Go Sarah
Simple yet customizable bot framework written in Go.
Stars: ✭ 188 (+45.74%)
Mutual labels:  bot-framework, slack-bot, slackbot, slack
Intelligo
🤖 Chatbot Framework for Node.js.
Stars: ✭ 347 (+168.99%)
Mutual labels:  bots, bot-framework, slack-bot, slack
slack widgets
An abstraction of the JSON structure needed to create widgets in Slack message attachments
Stars: ✭ 14 (-89.15%)
Mutual labels:  slack, slackbot, slack-bot
SlackWebhooksGithubCrawler
Search for Slack Webhooks token publicly exposed on Github
Stars: ✭ 21 (-83.72%)
Mutual labels:  slack, slackbot, slack-bot
iou-slack-bot
💸 IOU Slack Bot - Keep track of your debts with your peers.
Stars: ✭ 13 (-89.92%)
Mutual labels:  slack, slackbot, slack-bot
Norrisbot
a Slack bot that kicks asses (roundhouse-kicks to be accurate...)
Stars: ✭ 134 (+3.88%)
Mutual labels:  bots, slack-bot, slack
slackblocks
🎲 Python API for Building Messages Using the Slack Block Kit API
Stars: ✭ 32 (-75.19%)
Mutual labels:  slack, slack-bot, slack-api
Java Slack Sdk
Slack Developer Kit (including Bolt for Java) for any JVM language
Stars: ✭ 393 (+204.65%)
Mutual labels:  slack-bot, slack-api, slack
git-slack-notify
Sends Slack notifications for new commits in Git repositories
Stars: ✭ 12 (-90.7%)
Mutual labels:  slack, slackbot, slack-bot
slackr
Simple shell command to send or pipe content to slack via webhooks. (To upload snippets or files use: www.github.com/a-sync/slackfu)
Stars: ✭ 41 (-68.22%)
Mutual labels:  slackbot, slack-bot, slack-api
Wc2018 Slack Bot
World Cup 2018 Slack Bot
Stars: ✭ 11 (-91.47%)
Mutual labels:  slack-bot, slackbot, slack
Obed Bot
🍴 Obed Slack Bot, na požiadanie kontroluje aktuálnu ponuku denného menu reštaurácii. [only for slovak|czech users]
Stars: ✭ 32 (-75.19%)
Mutual labels:  slack-bot, slackbot, slack
Slack Cli
Powerful Slack CLI via pure bash. Rich messaging, uploads, posts, piping, oh my!
Stars: ✭ 850 (+558.91%)
Mutual labels:  slack-bot, slack-api, slack
Slack Poster
Simple gem to post messages on Slack using web hooks.
Stars: ✭ 49 (-62.02%)
Mutual labels:  slackbot, slack-api, slack

Logo

Maintainable code for Slack interactive messages, modals, and home tabs.

Lightweight, zero-dependency JavaScript library for Slack Block Kit UI.

View the Docs »

Quick Start Guide · Request Feature · Report Bug

An example of using Block Builder


npm NPM codecov Maintainability

Block Builder helps you keep your Slack app code for UI maintainable, testable, and reusable. It has a simple builder syntax inspired by SwiftUI and lets you code the way you want to code.

⚡️   Features

  • Simple SwiftUI inspired syntax.
  • In-depth doc site at https://blockbuilder.dev.
  • Support for all current Slack Block Kit objects – Surfaces, Blocks, Elements, and Composition Objects (View Support).
  • TypeScript type definitions.
  • Super helpful JSDoc hints that include real-world explanations, Slack validation rules, and a direct link to the object's documentation on Slack's API doc site.
  • Output of the composed UI as either an object, JSON string, or array of blocks.
  • A printPreviewURL() method that outputs to the console a link to preview your UI on Slack's Block Kit Builder website.
  • Small size, with zero dependencies.

🚀   Coming Soon

  • Components, such as an Accordion module.
  • Configurable option to check Slack validation rules.
  • Guide for Slack apps with tips, tricks, and best practices.

🎁   Benefits

  • Write three times less code.
  • Build more sophistocated, elegant flows.
  • Design better UI architecture (works as a template engine).
  • Focus more on experience and code in your IDE than on reading Slack API docs.
  • Code the way you want to code – not forced into any single paradigm.
  • Easily integrate localizations into your app.

☎️ Let's Talk?

Feedback – love it! Aside from GitHub Issues, there are Slack channels available in popular bot communities to discuss Block Builder – we'll see you there! 🙌

💾   Installation

Using NPM:

npm install --save slack-block-builder

Using Yarn:

yarn add slack-block-builder

👾   Usage

For full documentation, make sure you head over to https://blockbuilder.dev.

Importing

At the top level of the library, there are a few objects exposed for import. You'll be using these to build out your UI:

import { Message, Blocks, Elements, Bits } from 'slack-block-builder';

You can also import, in place of Message, Modal or HomeTab.

Exposed Imports

Modal – Used to create a modal surface.

Message – Used to create a message surface.

HomeTab – Used to create a message surface.

Note that since you'll more often only be working with one surface per file, they are exposed individually, whereas the rest of the objects are grouped into categories.

Blocks – Layout blocks used to organize the UI.

Elements – UI elements that are used to capture user interaction.

Bits – These are composition objects and other bits and pieces from Slack's docs. Included are Attachment, Options, OptionGroup, and ConfirmationDialog. They felt like they were deserving of their own category.

Object Support and Reference

Below is a list of supported objects and how to access them in Block Builder:

Name Type Support Accessed Via
Home Tab Surface HomeTab()
Message Surface Message()
Modal Surface Modal()
Actions Block Blocks.Actions()
Context Block Blocks.Context()
Divider Block Blocks.Divider()
File Block Blocks.File()
Header Block Blocks.Header()
Image Block Blocks.Image()
Input Block Blocks.Input()
Section Block Blocks.Section()
Button Element ✅️ Elements.Button()
Checkboxes Element Elements.Checkboxes()
Date Picker Element Elements.DatePicker()
Time Picker Element Elements.TimePicker()
Image Element Elements.Img()
Overflow Menu Element Elements.OverflowMenu()
Radio Buttons Element Elements.RadioButtons()
Plain-Text Input Element Elements.TextInput()
Select Menus Element Elements.[Type]Select()
Multi-Select Menus Element Elements.[Type]MultiSelect()
Option Composition Object Bits.Option()
Confirm Dialog Composition Object Bits.ConfirmationDialog()
Option Group Composition Object Bits.OptionGroup()
Attachment Legacy Feature Bits.Attachment()

Creating a Simple Interactive Message

Let's take a look at how to compose an interactive message. Even though Slack now has modals, these have always been the basis for Slack apps.

We can create a piece of UI using only the setter methods:

import { Message, Blocks, Elements } from 'slack-block-builder';

const myMessage = ({ channel }) => {
  return Message()
    .channel(channel)
    .text('Alas, my friend.')
    .blocks(
      Blocks.Section()
        .text('One does not simply walk into Slack and click a button.'),
      Blocks.Section()
        .text('At least that\'s what my friend Slackomir said ⚔️'),
      Blocks.Divider(),
      Blocks.Actions()
        .elements(
          Elements.Button()
            .text('Sure One Does')
            .actionId('gotClicked')
            .danger(),
          Elements.Button()
            .text('One Does Not')
            .actionId('scaredyCat')
            .primary()))
    .asUser()
    .buildToJSON();
};

Alternatively (and preferably), we can combine both the setter methods and the params to shorten it:

import { Message, Blocks, Elements } from 'slack-block-builder';

const myShorterMessage = ({ channel }) => {
  return Message({ channel, text: 'Alas, my friend.' })
    .blocks(
      Blocks.Section({ text: 'One does not simply walk into Slack and click a button.' }),
      Blocks.Section({ text: 'At least that\'s what my friend Slackomir said ⚔️' }),
      Blocks.Divider(),
      Blocks.Actions()
        .elements(
          Elements.Button({ text: 'Sure One Does', actionId: 'gotClicked' })
            .danger(),
          Elements.Button({ text: 'One Does Not', actionId: 'scaredyCat' })
            .primary()))
    .asUser()
    .buildToJSON();
};

Both of these examples render the message below. And the best part? It only took 15 lines of code, as opposed to the 44 lines of JSON generated as a result.

An example of using Block Builder for Messages

View Example on Slack Block Kit Builder Website

Creating a Simple Modal

Let's take a look at how modals are created.

Here we'll also take a look at working with Bits. You'll see in this example that we're hardcoding the options in the select menu. There are, of course, better ways to handle that, by using the Array.map() method, but they are listed here separately to demonstrate the usage.

First, an example using just our setter methods:

import { Modal, Blocks, Elements, Bits } from 'slack-block-builder';

const myModal = () => {
  return Modal()
    .title('PizzaMate')
    .blocks(
      Blocks.Section()
        .text('Hey there, colleague!'),
      Blocks.Section()
        .text('Hurray for corporate pizza! Let\'s get you fed and happy 🍕'),
      Blocks.Input()
        .label('What can we call you?')
        .element(
          Elements.TextInput()
            .placeholder('Hi, my name is... (What?!) (Who?!)')
            .actionId('name')),
      Blocks.Input()
        .label('Which floor are you on?')
        .element(
          Elements.TextInput()
            .placeholder('HQ – Fifth Floor')
            .actionId('floor')),
      Blocks.Input()
        .label('What\'ll you have?')
        .element(
          Elements.StaticSelect()
            .placeholder('Choose your favorite...')
            .actionId('item')
            .options(
              Bits.Option().text(':cheese_wedge: With Cheeze').value('012'),
              Bits.Option().text('🐟 With Anchovies').value('013'),
              Bits.Option().text('🍪 With Scooby Snacks').value('014'),
              Bits.Option().text('🍺 I Prefer Steak and Beer').value('015'))))
    .submit('Get Fed')
    .buildToJSON();
};

Alternatively (and preferably), we can combine both the setter methods and the params to shorten it:

import { Modal, Blocks, Elements, Bits } from 'slack-block-builder';

const myShorterModal = () => {
  return Modal({ title: 'PizzaMate', submit: 'Get Fed' })
    .blocks(
      Blocks.Section({ text: 'Hey there, colleague!' }),
      Blocks.Section({ text: 'Hurray for corporate pizza! Let\'s get you fed and happy 🍕' }),
      Blocks.Input({ label: 'What can we call you?' })
        .element(
          Elements.TextInput({ placeholder: 'Hi, my name is... (What?!) (Who?!)' })
            .actionId('name')),
      Blocks.Input({ label: 'Which floor are you on?' })
        .element(
          Elements.TextInput({ placeholder: 'HQ – Fifth Floor' })
            .actionId('floor')),
      Blocks.Input({ label: 'What\'ll you have?' })
        .element(
          Elements.StaticSelect({ placeholder: 'Choose your favorite...' })
            .actionId('item')
            .options(
              Bits.Option({ text: ':cheese_wedge: With Cheeze', value: '012' }),
              Bits.Option({ text: '🐟 With Anchovies', value: '013' }),
              Bits.Option({ text: '🍪 With Scooby Snacks', value: '014' }),
              Bits.Option({ text: '🍺 I Prefer Steak and Beer', value: '015' }))))
    .buildToJSON();
};

Both of these examples render the modal below.

An example of using Block Builder for Modals

View Example on Slack Block Kit Builder Website

🔗   Other Useful Slack-Related Projects

Bolt for JavaScript – A simple framework for building Slack apps, developed by Slack themselves.

Node Slack SDK – A great and powerful SDK for building Slack Apps from the ground up.

JSX-Slack – Awesome way to create Slack Block Kit UIs using JSX.

🔥   Acknowledgements

@bravecow Taras Neporozhniy (@bravecow) - For mentorship over the years!

@ft502 Alexey Chernyshov (@ft502 on Dribbble) - For such a beautiful logo!

@slackhq SlackHQ (@slackhq) - For such a wonderful product and API!

✒️   Author

@raycharius Ray East (@raycharius) - Huge Fan of Slack and Block Builder Maintainer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].