Skip to content
This repository has been archived by the owner on Jan 28, 2019. It is now read-only.

Commit

Permalink
Send threaded messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Zignego committed Jun 14, 2017
1 parent 756c5ff commit 453e0ff
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Sources/SKRTMAPI/SKRTMAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,38 @@ public final class SKRTMAPI: RTMDelegate {
rtm.disconnect()
}

public func sendMessage(_ message: String, channelID: String, threadTs: String? = nil) throws {
public func sendMessage(_ message: String, channelID: String) throws {
guard connected else {
throw SlackError.rtmConnectionError
}
do {
let string = try format(message: message, channel: channelID, threadTs: threadTs)
let string = try format(message: message, channel: channelID)
try rtm.sendMessage(string)
} catch let error {
throw error
}
}

private func format(message: String, channel: String, threadTs: String?) throws -> String {
public func sendThreadedMessage(_ message: String, channelID: String, threadTs: String, broadcastReply: Bool = false) throws {
guard connected else {
throw SlackError.rtmConnectionError
}
do {
let string = try format(message: message, channel: channelID, threadTs: threadTs, broadcastReply: broadcastReply)
try rtm.sendMessage(string)
} catch let error {
throw error
}
}

private func format(message: String, channel: String, threadTs: String? = nil, broadcastReply: Bool = false) throws -> String {
let json: [String: Any?] = [
"id": Date().slackTimestamp,
"type": "message",
"channel": channel,
"text": message.slackFormatEscaping,
"thread_ts": threadTs
"thread_ts": threadTs,
"broadcastReply": broadcastReply
]
guard
let data = try? JSONSerialization.data(withJSONObject: filterNilParameters(json), options: []),
Expand Down

0 comments on commit 453e0ff

Please sign in to comment.