Code Monkey home page Code Monkey logo

slack-message-client's Introduction

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

slack-message-client's People

Contributors

mplew-is avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.