Send messages to Slack from Swift.
- [x] Send simple text only messages
- [x] Add attachements with colours and fields
- [x] Fully tested
See Slack API documentation for more information.
To get a feel for what is possible with SlackHook you can run the built-in demo:
swift build swift run SlackHook <WebHook URL>
<WebHook URL> with the a valid Slack WebHook URL and you will see a demo message posted similar to the following:
SlackHook should be simple to use and have a self explanatory API.
import SlackHookCore let slackHook = try SlackHook(from: "<WebHook URL>") let message = Message(text: "Hello from Swift", username: "SlackHook", attachments: nil) try! slackHook.post(message)
NOTE: Assuming you have a runloop, otherwise
RunLoop.main.run() will be needed. See Sources/SlackHook/main.swift for how this is used in the command line tool.
- Swift 4.1+ / Xcode 9.4.1+
- iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
- Ubuntu 14.04 / Ubuntu 16.04 / Ubuntu 16.10
Swift Package Manager
.package(url: "https://gitlab.com/optimisedlabs/slackhook.git", .from: "0.3.0")
.upToNextMinor(from: "0.3.0") might be better whilst the API stablises.
Acknowledgements and thanks
Whilst this is by no means an exhaustive list, I would like to thank:
- Apple, standing on the shoulders of giants...
- Excellent article on Building a command line tool using the Swift Package Manager by John Sundell
- httpbin, a simple HTTP Request & Response Service. Such a useful tool, cannot recommend enough.
- Using XCTAssertThrowsError in your Swift tests for testing the right
SlackHook is released under the Apache 2.0 license. See LICENSE for details.