Skip to content

Commit 1bf31dc

Browse files
TheIrritainerMichael TielCopilot
authored
feat(upload): Enable file uploads inside threads (#188)
* Adding threadts to allow posting to a thread * CS fix * tested uploading in thread * Update phpunit.xml.dist Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/WritingTest.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Client.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Michael Tiel <michael.tiel@onthatass.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 59e617a commit 1bf31dc

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
<php>
1111
<ini name="error_reporting" value="-1" />
1212
<!--<server name="SLACK_TOKEN" value="edit_me" />-->
13+
<!-- should be the channel ID, not name -->
1314
<!--<server name="SLACK_TEST_CHANNEL" value="edit_me" />-->
15+
<!-- set this to test uploads in a thread -->
16+
<!--<server name="SLACK_TEST_THREAD_TS" value="edit_me" />-->
1417
</php>
1518

1619
<testsuites>

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function iterate(string $method, array $arguments): iterable
9999
* ]
100100
* @param string $channelId The Slack channel ID to upload files to (e.g., 'C12345678').
101101
* @param string|null $initialComment optional comment to add with the upload
102+
* @param string|null $threadTs optional thread_ts (Slack thread timestamp) to attach the upload to a thread
102103
*
103104
* @throws \RuntimeException if upload or Slack API interaction fails
104105
* @throws \JsonException
@@ -114,6 +115,7 @@ public function filesUploadV2(
114115
array $files,
115116
string $channelId,
116117
?string $initialComment = null,
118+
?string $threadTs = null,
117119
): FilesCompleteUploadExternalPostResponsedefault|FilesCompleteUploadExternalPostResponse200|null {
118120
$filesPayload = [];
119121

@@ -161,6 +163,7 @@ public function filesUploadV2(
161163
[
162164
'files' => json_encode($filesPayload, \JSON_THROW_ON_ERROR),
163165
'channel_id' => $channelId,
166+
'thread_ts' => $threadTs,
164167
'initial_comment' => $initialComment,
165168
]
166169
)

tests/WritingTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public function testItCanFileGetUploadUrlExternal(): void
174174
$filePath = __DIR__ . '/resources/' . $fileName;
175175
$fileStream = Stream::create(fopen($filePath, 'r'));
176176
$fileSize = $fileStream->getSize();
177+
$threadTs = $_SERVER['SLACK_TEST_THREAD_TS'] ?? null;
177178

178179
$response = $client->filesGetUploadUrlExternal(
179180
[
@@ -191,7 +192,7 @@ public function testItCanFileGetUploadUrlExternal(): void
191192

192193
$uploadResponse = $client->filesUploadV2([
193194
['path' => $filePath, 'title' => 'Test image', 'alt_text' => 'Test image'],
194-
], $_SERVER['SLACK_TEST_CHANNEL'], 'Uploaded with the 2025 API.');
195+
], $_SERVER['SLACK_TEST_CHANNEL'], 'Uploaded with the 2025 API.', $threadTs);
195196

196197
self::assertTrue($uploadResponse->getOk());
197198
}

0 commit comments

Comments
 (0)