##iOS/OS X Slack Client Library ###Description This is a Slack client library for iOS and OS X written in Swift. It's intended to expose all of the functionality of Slack's Real Time Messaging API as well as the web APIs that are accessible by bot users.
###Installation ####Swift Package Manager Add SlackKit to your Package.swift
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 1)
]
)
Run swift-build
on your application’s main directory.
####CocoaPods Add the pod to your podfile:
pod 'SlackKit'
and run
pod install
To use the library in your project import it:
import SlackKit
###Usage To use SlackKit you'll need a bearer token which identifies a single user. You can generate a full access token or create one using OAuth 2.
Once you have a token, initialize a client instance using it:
let client = Client(apiToken: "YOUR_SLACK_API_TOKEN")
If you want to receive messages from the Slack RTM API, connect to it.
client.connect()
You can also set options for a ping/pong interval, timeout interval, and automatic reconnection:
client.connect(pingInterval: 2, timeout: 10, reconnect: false)
Once connected, the client will begin to consume any messages sent by the Slack RTM API.
####Web API Methods SlackKit currently supports the a subset of the Slack Web APIs that are available to bot users:
- api.test
- auth.test
- channels.history
- channels.info
- channels.list
- channels.mark
- channels.setPurpose
- channels.setTopic
- chat.delete
- chat.postMessage
- chat.update
- emoji.list
- files.comments.add
- files.comments.edit
- files.comments.delete
- files.delete
- files.upload
- groups.close
- groups.history
- groups.info
- groups.list
- groups.mark
- groups.open
- groups.setPurpose
- groups.setTopic
- im.close
- im.history
- im.list
- im.mark
- im.open
- mpim.close
- mpim.history
- mpim.list
- mpim.mark
- mpim.open
- pins.add
- pins.list
- pins.remove
- reactions.add
- reactions.get
- reactions.list
- reactions.remove
- rtm.start
- stars.add
- stars.remove
- team.info
- users.getPresence
- users.info
- users.list
- users.setActive
- users.setPresence
They can be accessed through a Client object’s webAPI
property:
client.webAPI.authenticationTest({
(authenticated) -> Void in
print(authenticated)
}){(error) -> Void in
print(error)
}
####Delegate methods
To receive delegate callbacks for certain events, register an object as the delegate for those events:
client.slackEventsDelegate = self
There are a number of delegates that you can set to receive callbacks for certain events.
#####SlackEventsDelegate
func clientConnected()
func clientDisconnected()
func preferenceChanged(preference: String, value: AnyObject)
func userChanged(user: User)
func presenceChanged(user: User?, presence: String?)
func manualPresenceChanged(user: User?, presence: String?)
func botEvent(bot: Bot)
#####MessageEventsDelegate
func messageSent(message: Message)
func messageReceived(message: Message)
func messageChanged(message: Message)
func messageDeleted(message: Message?)
#####ChannelEventsDelegate
func userTyping(channel: Channel?, user: User?)
func channelMarked(channel: Channel, timestamp: String?)
func channelCreated(channel: Channel)
func channelDeleted(channel: Channel)
func channelRenamed(channel: Channel)
func channelArchived(channel: Channel)
func channelHistoryChanged(channel: Channel)
func channelJoined(channel: Channel)
func channelLeft(channel: Channel)
#####DoNotDisturbEventsDelegate
doNotDisturbUpdated(dndStatus: DoNotDisturbStatus)
doNotDisturbUserUpdated(dndStatus: DoNotDisturbStatus, user: User?)
#####GroupEventsDelegate
func groupOpened(group: Channel)
#####FileEventsDelegate
func fileProcessed(file: File)
func fileMadePrivate(file: File)
func fileDeleted(file: File)
func fileCommentAdded(file: File, comment: Comment)
func fileCommentEdited(file: File, comment: Comment)
func fileCommentDeleted(file: File, comment: Comment)
#####PinEventsDelegate
func itemPinned(item: Item?, channel: Channel?)
func itemUnpinned(item: Item?, channel: Channel?)
#####StarEventsDelegate
func itemStarred(item: Item, star: Bool)
#####ReactionEventsDelegate
func reactionAdded(reaction: String?, item: Item?, itemUser: String?)
func reactionRemoved(reaction: String?, item: Item?, itemUser: String?)
#####TeamEventsDelegate
func teamJoined(user: User)
func teamPlanChanged(plan: String)
func teamPreferencesChanged(preference: String, value: AnyObject)
func teamNameChanged(name: String)
func teamDomainChanged(domain: String)
func teamEmailDomainChanged(domain: String)
func teamEmojiChanged()
#####SubteamEventsDelegate
func subteamEvent(userGroup: UserGroup)
func subteamSelfAdded(subteamID: String)
func subteamSelfRemoved(subteamID: String)
###Get In Touch @pvzig