@@ -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