Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
Sources
README.md
SKRTMAPI.xcconfig

README.md

SKRTMAPI

Connect to the Slack Real Time Messaging API in Swift.

Installation

Swift Package Manager Add SlackKit as a dependency to your Package.swift and specify SKRTMAPI as a target dependency:
import PackageDescription
  
let package = Package(
    name: "SampleApp",
    products: [
        .executable(
            name: "SampleApp",
            targets: ["SampleApp"]),
    ],
    dependencies: [
        .package(url: "https://github.com/pvzig/SlackKit.git", .upToNextMinor(from: "4.3.0")),
    ],
    targets: [
        .target(
            name: "SampleApp",
            dependencies: ["SKRTMAPI"])
    ]
)

When built using Swift Package Manager, SKRTMAPI includes the vapor websocket framework by default which requires libressl.

You can install it with homebrew: brew install libressl

If you'd like to use SPM without vapor websocket, you can modify the Package.swift file to exclude it:

let SKRTMAPI: Target = .target(name: "SKRTMAPI",
                               path: "SKRTMAPI/Sources",
                               exclude: ["Conformers/VaporEngineRTM.swift"])

#if os(macOS)
SKRTMAPI.dependencies = [
    "SKCore",
    "SKWebAPI",
    "Starscream"
]
Carthage Add SlackKit to your Cartfile:
github "pvzig/SlackKit"

and run

carthage bootstrap

Drag the built SKRTMAPI.framework and it's dependencies SKCore.framework, SKWebAPI.framework, and Starscream.framework into your Xcode project.

CocoaPods Add SKRTMAPI to your Podfile:
use_frameworks!
pod 'SlackKit/SKRTMAPI'

Usage

To use the library in your project import it:

Carthage & SPM

import SKRTMAPI

CocoaPods

import SlackKit

The Basics

Initialize an instance of SKRTMAPI with a Slack auth token:

let rtm = SKRTMAPI(token: "xoxb-SLACK_AUTH_TOKEN")
rtm.connect()

If your bot doesn't need any state information when you connect, pass false for the withInfo parameter:

let rtm = SKRTMAPI(token: "xoxb-SLACK_AUTH_TOKEN")
rtm.connect(withInfo: false)

Customize the connection with RTMOptions:

let options = RTMOptions(simpleLatest: false, noUnreads: false, mpimAware: true, pingInterval: 30, timeout: 300, reconnect: true)
let rtm = SKRTMAPI(token: "xoxb-SLACK_AUTH_TOKEN", options: options)
rtm.connect()

Provide your own web socket implementation by conforming to RTMWebSocket:

public protocol RTMWebSocket {
    init()
    var delegate: RTMDelegate? { get set }
    func connect(url: URL)
    func disconnect()
    func sendMessage(_ message: String) throws
}
let rtmWebSocket = YourRTMWebSocket()
let rtm = SKRTMAPI(token: "xoxb-SLACK_AUTH_TOKEN", rtm: rtmWebSocket)
rtm.connect()
You can’t perform that action at this time.