Slack message generator and API client, written in Swift with Result Builders and Concurrency

Last update: Jul 30, 2022

Slack Message Client

This package provides a Swift object model for a Slack Block Kit message, as well as a Result Builder convenience interface for easy message creation. Also provides an asynchronous API client for sending messages based on the async-http-client from the Swift Server Workgroup.

This is still in extremely early development, and only currently supports sending messages and a narrow subset of the full Block Kit API.

Quick Start

See the command-line interface example for an example implementation runnable from the command line, with configurable message text.

Add to your Package.Swift:

...
	dependencies: [
		...
		.package(url: "https://github.com/MPLew-is/slack-message-client", branch: "main"),
	],
	targets: [
		...
		.target(
			...
			dependencies: [
				...
				.product(name: "BlockKitMessage", package: "slack-message-client"),
				.product(name: "SlackMessageClient", package: "slack-message-client"),
			]
		),
		...
	]
]

Create and send a message:

import BlockKitMessage
import SlackMessageClient

@main
struct SlackMessageExample {
	static func main() async throws {
		let message = Message.build {
			Header("Header")

			Section(mrkdwn: "Section")

			Context.build {
				Image(url: "https://example.com", alternateText: "Alt text")
				Mrkdwn("User")
			}
		}

		let client = SlackMessageClient(authToken: "YOUR_SLACK_BOT_TOKEN")
		try await client.post(message, to: "YOUR_SLACK_CHANNEL_ID")
	}
}

(See the command-line interface example for more detailed instructions on how to set up a Slack app and get the required authentication/configuration values)

Targets provided

  • BlockKitMessage: object model for a Slack Block Kit message, if you just want to create messages but not send them

    • A Message object conforms to Codable, so you can use this to just generate the JSON expected by Slack, for instance
  • SlackApiClient: a thin wrapper around an AsyncHTTPClient which auto-injects the correct headers needed for the Slack API

    • You can use this by itself if you want to perform actions against the Slack API other than chat.postMessage
  • SlackMessageClient: full client integrating the previous two targets into a simple interface for sending messages to a channel

Features supported and planned

If you don't see something on this list, it's not currently planned. Feel free to file an issue/PR to change that though.

Block Kit

  • Top-level message objects

    • Basic integration (blocks argument)
    • Alternate text (text argument)
  • Mrkdwn result builder

    • Basic support for mrkdwn embedded in a string is already present, this will just provide a better way to build complicated messages
  • Header blocks

  • Section blocks

    • Basic support (text)
    • Fields and accessories not currently planned
  • Context blocks

  • Divider blocks

  • Image blocks

  • Actions, file, and input blocks not currently planned

Slack message client

  • chat.postMessage method integration

    • channel argument
    • Attachments and optional arguments not currently planned
  • Sending Message object

  • Sending raw JSON blocks generated externally

  • Optional credentials verification on initialization to fail quickly (api.test method)

  • Better parsing and handling of HTTP and Slack API errors

GitHub

https://github.com/MPLew-is/slack-message-client
You might also like...

Functional Concurrency Primitives

Concurrent Concurrent is a collection of functional concurrency primitives inspired by Concurrent ML and Concurrent Haskell. Traditional approaches to

Mar 9, 2022

AsyncOperators brings some features of RxSwift/Combine to Structured Concurrency

AsyncOperators brings some features of RxSwift/Combine to Structured Concurrency, such as combineLatest and distinctUntilChanged.

Jan 18, 2022

Automatically generate GraphQL queries and decode results into Swift objects, and also interact with arbitrary GitHub API endpoints

GitHub API and GraphQL Client This package provides a generic GitHub API client (GithubApiClient) as well as Codable-like GitHub GraphQL querying and

Aug 2, 2022

Schedule timing task in Swift using a fluent API. (A friendly alternative to Timer)

Schedule timing task in Swift using a fluent API. (A friendly alternative to Timer)

Schedule(简体中文) Schedule is a timing tasks scheduler written in Swift. It allows you run timing tasks with elegant and intuitive syntax. Features Elega

Aug 1, 2022

Swift TableView pagination with async API request.

Swift TableView pagination with async API request.

SwiftTableViewPagination Swift TableView pagination with async API request. Output UML Create puml file. $ cd SwiftTableViewPagination/scripts/swiftum

Dec 26, 2021

Throttle massive number of inputs in a single drop of one line API.

Throttle massive number of inputs in a single drop of one line API.

Icon credits: Lorc, Delapouite & contributors Throttler Throttler is a library that throttles unnecessarily repeated and massive inputs until the last

Jun 24, 2022

PixabayImageSearchSample - SwiftUI + LazyVGrid + Pixabay API + Codable + sync/async Sample

PixabayImageSearchSample - SwiftUI + LazyVGrid + Pixabay API + Codable + sync/async Sample

PixabayImageSearchSample SwiftUI + LazyVGrid + Pixabay API + Codable + sync/asyn

Jan 13, 2022

Futures is a cross-platform framework for simplifying asynchronous programming, written in Swift.

Futures Futures is a cross-platform framework for simplifying asynchronous programming, written in Swift. It's lightweight, fast, and easy to understa

Jan 29, 2022

A wrapper of Grand Central Dispatch written in Swift

GCD A wrapper of Grand Central Dispatch written in Swift. Examples gcd // submit your code for asynchronous execution on a global queue with high prio

May 19, 2022
A complete set of primitives for concurrency and reactive programming on Swift
A complete set of primitives for concurrency and reactive programming on Swift

A complete set of primitives for concurrency and reactive programming on Swift 1.4.0 is the latest and greatest, but only for Swift 4.2 and 5.0 use 1.

Jan 29, 2022
A Swift DSL that allows concise and effective concurrency manipulation
A Swift DSL that allows concise and effective concurrency manipulation

NOTE Brisk is being mothballed due to general incompatibilities with modern version of Swift. I recommend checking out ReactiveSwift, which solves man

May 24, 2019
⚡️ Fast async task based Swift framework with focus on type safety, concurrency and multi threading
⚡️ Fast async task based Swift framework with focus on type safety, concurrency and multi threading

Our apps constantly do work. The faster you react to user input and produce an output, the more likely is that the user will continue to use your appl

Aug 4, 2022
The projects and materials that accompany the Modern Concurrency in Swift book

Modern Concurrency in Swift: Materials This repo contains all the downloadable materials and projects associated with the Modern Concurrency in Swift

Aug 7, 2022
Tools for using Swift Concurrency on macOS 10.15 Catalina, iOS 13, tvOS 13, and watchOS 6.

ConcurrencyCompatibility Tools for using Swift Concurrency on macOS 10.15 Catalina, iOS 13, tvOS 13, and watchOS 6. Xcode 13.2 adds backwards deployme

May 17, 2022
Several synchronization primitives and task synchronization mechanisms introduced to aid in modern swift concurrency.

AsyncObjects Several synchronization primitives and task synchronization mechanisms introduced to aid in modern swift concurrency. Overview While Swif

Aug 8, 2022
Swift concurrency collection support

AsyncCollections Functions for running async processes on Swift Collections ForEach Run an async function on every element of a Sequence. await array.

Jul 11, 2022
An introduction to using Swift's new concurrency features in SwiftUI
 An introduction to using Swift's new concurrency features in SwiftUI

SwiftUI Concurrency Essentials An introduction to using Swift's new concurrency features in SwiftUI Discuss with me · Report Bug · Request Feature Art

Jul 24, 2022
Type-safe networking with Swift Concurrency

AsyncRequest AsyncRequest is a type-safe framework for building a suite of requests to communicate with an API, built on top of Swift Concurrency. Ins

Feb 9, 2022
A declarative state management and dependency injection library for SwiftUI x Concurrency
A declarative state management and dependency injection library for SwiftUI x Concurrency

A declarative state management and dependency injection library for SwiftUI x Concurrency

Aug 3, 2022