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

Commit 062939e

Browse files
author
Peter Zignego
committed
Send threaded message
1 parent 0261ffa commit 062939e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Sources/SKRTMAPI/SKRTMAPI.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,28 @@ public final class SKRTMAPI: RTMDelegate {
9494
rtm.disconnect()
9595
}
9696

97-
public func sendMessage(_ message: String, channelID: String) throws {
97+
public func sendMessage(_ message: String, channelID: String, threadTs: String? = nil) throws {
9898
guard connected else {
9999
throw SlackError.rtmConnectionError
100100
}
101101
do {
102-
let string = try format(message: message, channel: channelID)
102+
let string = try format(message: message, channel: channelID, threadTs: threadTs)
103103
try rtm.sendMessage(string)
104104
} catch let error {
105105
throw error
106106
}
107107
}
108108

109-
private func format(message: String, channel: String) throws -> String {
110-
let json: [String: Any] = [
109+
private func format(message: String, channel: String, threadTs: String?) throws -> String {
110+
let json: [String: Any?] = [
111111
"id": Date().slackTimestamp,
112112
"type": "message",
113113
"channel": channel,
114-
"text": message.slackFormatEscaping
114+
"text": message.slackFormatEscaping,
115+
"thread_ts": threadTs
115116
]
116117
guard
117-
let data = try? JSONSerialization.data(withJSONObject: json, options: []),
118+
let data = try? JSONSerialization.data(withJSONObject: filterNilParameters(json), options: []),
118119
let str = String(data: data, encoding: String.Encoding.utf8)
119120
else {
120121
throw SlackError.clientJSONError

0 commit comments

Comments
 (0)