|
13 | 13 | extract_actor_team_id, |
14 | 14 | extract_actor_user_id, |
15 | 15 | extract_function_execution_id, |
| 16 | + extract_thread_ts, |
16 | 17 | ) |
17 | 18 |
|
18 | 19 |
|
@@ -111,6 +112,143 @@ def teardown_method(self): |
111 | 112 | }, |
112 | 113 | ] |
113 | 114 |
|
| 115 | + thread_ts_event_requests = [ |
| 116 | + { |
| 117 | + "event": { |
| 118 | + "type": "app_mention", |
| 119 | + "channel": "C111", |
| 120 | + "user": "U111", |
| 121 | + "ts": "123.420", |
| 122 | + "thread_ts": "123.456", |
| 123 | + }, |
| 124 | + }, |
| 125 | + { |
| 126 | + "event": { |
| 127 | + "type": "message", |
| 128 | + "channel": "C111", |
| 129 | + "user": "U111", |
| 130 | + "ts": "123.420", |
| 131 | + "thread_ts": "123.456", |
| 132 | + }, |
| 133 | + }, |
| 134 | + { |
| 135 | + "event": { |
| 136 | + "type": "message", |
| 137 | + "subtype": "bot_message", |
| 138 | + "channel": "C111", |
| 139 | + "bot_id": "B111", |
| 140 | + "ts": "123.420", |
| 141 | + "thread_ts": "123.456", |
| 142 | + }, |
| 143 | + }, |
| 144 | + { |
| 145 | + "event": { |
| 146 | + "type": "message", |
| 147 | + "subtype": "file_share", |
| 148 | + "channel": "C111", |
| 149 | + "user": "U111", |
| 150 | + "ts": "123.420", |
| 151 | + "thread_ts": "123.456", |
| 152 | + }, |
| 153 | + }, |
| 154 | + { |
| 155 | + "event": { |
| 156 | + "type": "message", |
| 157 | + "subtype": "thread_broadcast", |
| 158 | + "channel": "C111", |
| 159 | + "user": "U111", |
| 160 | + "ts": "123.420", |
| 161 | + "thread_ts": "123.456", |
| 162 | + "root": {"thread_ts": "123.420"}, |
| 163 | + }, |
| 164 | + }, |
| 165 | + { |
| 166 | + "event": { |
| 167 | + "type": "link_shared", |
| 168 | + "channel": "C111", |
| 169 | + "user": "U111", |
| 170 | + "thread_ts": "123.456", |
| 171 | + "links": [{"url": "https://example.com"}], |
| 172 | + }, |
| 173 | + }, |
| 174 | + { |
| 175 | + "event": { |
| 176 | + "type": "message", |
| 177 | + "subtype": "message_changed", |
| 178 | + "channel": "C111", |
| 179 | + "message": { |
| 180 | + "type": "message", |
| 181 | + "user": "U111", |
| 182 | + "text": "edited", |
| 183 | + "ts": "123.420", |
| 184 | + "thread_ts": "123.456", |
| 185 | + }, |
| 186 | + }, |
| 187 | + }, |
| 188 | + { |
| 189 | + "event": { |
| 190 | + "type": "message", |
| 191 | + "subtype": "message_changed", |
| 192 | + "channel": "C111", |
| 193 | + "message": { |
| 194 | + "type": "message", |
| 195 | + "user": "U111", |
| 196 | + "text": "edited", |
| 197 | + "ts": "123.420", |
| 198 | + "thread_ts": "123.456", |
| 199 | + }, |
| 200 | + "previous_message": { |
| 201 | + "type": "message", |
| 202 | + "user": "U111", |
| 203 | + "text": "deleted", |
| 204 | + "ts": "123.420", |
| 205 | + "thread_ts": "123.420", |
| 206 | + }, |
| 207 | + }, |
| 208 | + }, |
| 209 | + { |
| 210 | + "event": { |
| 211 | + "type": "message", |
| 212 | + "subtype": "message_deleted", |
| 213 | + "channel": "C111", |
| 214 | + "previous_message": { |
| 215 | + "type": "message", |
| 216 | + "user": "U111", |
| 217 | + "text": "deleted", |
| 218 | + "ts": "123.420", |
| 219 | + "thread_ts": "123.456", |
| 220 | + }, |
| 221 | + }, |
| 222 | + }, |
| 223 | + ] |
| 224 | + |
| 225 | + no_thread_ts_requests = [ |
| 226 | + { |
| 227 | + "event": { |
| 228 | + "type": "reaction_added", |
| 229 | + "user": "U111", |
| 230 | + "reaction": "thumbsup", |
| 231 | + "item": {"type": "message", "channel": "C111", "ts": "123.420"}, |
| 232 | + }, |
| 233 | + }, |
| 234 | + { |
| 235 | + "event": { |
| 236 | + "type": "channel_created", |
| 237 | + "channel": {"id": "C222", "name": "test", "created": 1678455198}, |
| 238 | + }, |
| 239 | + }, |
| 240 | + { |
| 241 | + "event": { |
| 242 | + "type": "message", |
| 243 | + "channel": "C111", |
| 244 | + "user": "U111", |
| 245 | + "text": "hello", |
| 246 | + "ts": "123.420", |
| 247 | + }, |
| 248 | + }, |
| 249 | + {}, |
| 250 | + ] |
| 251 | + |
114 | 252 | slack_connect_authorizations = [ |
115 | 253 | { |
116 | 254 | "enterprise_id": "INSTALLED_ENTERPRISE_ID", |
@@ -223,10 +361,10 @@ def teardown_method(self): |
223 | 361 | "type": "message", |
224 | 362 | "text": "<@INSTALLED_BOT_USER_ID> Hey!", |
225 | 363 | "user": "USER_ID_ACTOR", |
226 | | - "ts": "1678455198.838499", |
| 364 | + "ts": "123.456", |
227 | 365 | "team": "TEAM_ID_ACTOR", |
228 | 366 | "channel": "C111", |
229 | | - "event_ts": "1678455198.838499", |
| 367 | + "event_ts": "123.456", |
230 | 368 | "channel_type": "channel", |
231 | 369 | }, |
232 | 370 | "type": "event_callback", |
@@ -337,6 +475,47 @@ def test_function_inputs_extraction(self): |
337 | 475 | inputs = extract_function_inputs(req) |
338 | 476 | assert inputs == {"customer_id": "Ux111"} |
339 | 477 |
|
| 478 | + def test_extract_thread_ts(self): |
| 479 | + for req in self.thread_ts_event_requests: |
| 480 | + thread_ts = extract_thread_ts(req) |
| 481 | + assert thread_ts == "123.456", f"Expected thread_ts for {req}" |
| 482 | + |
| 483 | + def test_extract_thread_ts_fail(self): |
| 484 | + for req in self.no_thread_ts_requests: |
| 485 | + thread_ts = extract_thread_ts(req) |
| 486 | + assert thread_ts is None, f"Expected None for {req}" |
| 487 | + |
| 488 | + def test_extract_thread_ts_edge_cases(self): |
| 489 | + # message_changed where only previous_message has thread_ts (no message key) |
| 490 | + req = { |
| 491 | + "event": { |
| 492 | + "type": "message", |
| 493 | + "subtype": "message_deleted", |
| 494 | + "channel": "C111", |
| 495 | + "previous_message": { |
| 496 | + "type": "message", |
| 497 | + "ts": "1678455205.000000", |
| 498 | + "thread_ts": "123.456", |
| 499 | + }, |
| 500 | + }, |
| 501 | + } |
| 502 | + assert extract_thread_ts(req) == "123.456" |
| 503 | + |
| 504 | + # Payload with thread_ts directly at root level (non-event payload) |
| 505 | + req = {"thread_ts": "123.456"} |
| 506 | + assert extract_thread_ts(req) == "123.456" |
| 507 | + |
| 508 | + # Event with thread_ts as empty string (truthy check: empty string is falsy) |
| 509 | + req = { |
| 510 | + "event": { |
| 511 | + "type": "message", |
| 512 | + "channel": "C111", |
| 513 | + "thread_ts": "", |
| 514 | + }, |
| 515 | + } |
| 516 | + # Empty string is falsy, so .get() returns "" but `is not None` is True |
| 517 | + assert extract_thread_ts(req) == "" |
| 518 | + |
340 | 519 | def test_is_enterprise_install_extraction(self): |
341 | 520 | for req in self.requests: |
342 | 521 | should_be_false = extract_is_enterprise_install(req) |
|
0 commit comments