Swiftpack.co - SwiftBlocksUI/SwiftBlocksUI as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
SwiftBlocksUI/SwiftBlocksUI
Develop interactive Slack messages and modals using a SwiftUI like declarative style
.package(url: "https://github.com/SwiftBlocksUI/SwiftBlocksUI.git", from: "0.9.3")

SwiftBlocksUI

SwiftBlocksUI is a way to write interactive Slack messages and modal dialogs (also known as Slack "applications") using a SwiftUI like declarative style.

A blog article containing SwiftBlocksUI tutorials: Instant “SwiftUI” Flavoured Slack Apps.
Documentation, examples: SlashCows, AvocadoToast, ClipIt!.

This is what a full application looks like:

#!/usr/bin/swift sh
import SwiftBlocksUI // @SwiftBlocksUI

dotenv.config()

struct ClipItView: Blocks {

  @State(\.messageText) var messageText
  @State var importance = "medium"
  
  var body: some Blocks {
    View("Save it to ClipIt!") {
      TextEditor("Message Text", text: $messageText)
      
      Picker("Importance", selection: $importance) {
        "High 💎💎✨".tag("high")
        "Medium 💎"  .tag("medium")
        "Low ⚪️"     .tag("low")
      }
      
      Submit("CliptIt") {
        console.log("Clip:", messageText, importance)
      }
    }
  }
}

struct ClipIt: App {

  var body: some Endpoints {
    Use(logger("dev"), bodyParser.urlencoded(),
        sslCheck(verifyToken(allowUnsetInDebug: true)))
        
    MessageAction("clipit") {
      ClipItView()
    }
  }
}

try ClipIt.main()

Looks like this:

Documentation

There is a related blog entry going over SwiftBlocksUI: Instant “SwiftUI” Flavoured Slack Apps.

Block documentation and a lot more can be found within this repository: Documentation.

Examples:

  • SlashCows - Slack slash command that produces ASCII Cows. Moo!
  • AvocadoToast - An Avocado Toast ordering solution.
  • ClipIt! - Working on Messages.

Environment Variables

  • SLACK_ACCESS_TOKEN (the token required to send requests to Slack)
  • SLACK_VERIFICATION_TOKEN (shared secret with Slack to verify requests)
  • PORT (the port the app is going to start on, defaults to 1337)
  • LOG_SLACK_CLIENT_POSTS (set to 1 to log the JSON sent to Slack using SlackClient)
  • blocks.log.blocks (yes to log the structure of outgoing API blocks)
  • blocks.log.blocks.json (yes to log the raw JSON of outgoing blocks)
  • macro.core.numthreads
  • macro.core.iothreads
  • macro.core.retain.debug
  • macro.concat.maxsize
  • macro.streams.debug.rc
  • macro.router.debug
  • macro.router.matcher.debug

Requirements

On Linux this currently requires a Swift 5.3 environment (swiftc crash, might be SR-12543).

On macOS it should work with Swift 5.2 (aka Xcode 11) and up, though 5.3 has some additional conveniences.

Links

Who

SwiftBlocksUI is brought to you by the Always Right Institute and ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.

GitHub

link
Stars: 36
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Asynchronously Not
2 weeks ago

Adjustments for Swift 5.5, e.g. use @resultBuilder.

Updated dependencies to 5.5 capable versions.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics