Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send a Message/File to a Thread #119

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion PSSlack/Public/New-SlackMessage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

.PARAMETER IconUrl
URL to an image to use as the icon for this message.

If using a token, must be used in conjunction with as_user set to false, otherwise ignored.

See authorship details: https://api.slack.com/methods/chat.postMessage#authorship
Expand All @@ -46,6 +46,11 @@
.PARAMETER LinkNames
Find and link channel names and usernames.

.PARAMETER Thread
Optional thread where file is sent. Needs to be the parent thread id which is either the ts or thread_ts.

Can find a ts by querying https://api.slack.com/methods/conversations.history

.PARAMETER Parse
Change how messages are treated. Defaults to none

Expand Down Expand Up @@ -168,6 +173,7 @@
[string]$IconEmoji,
[switch]$AsUser,
[switch]$LinkNames,
[string]$Thread,

[validateset('full','none')]
[string]$Parse,
Expand Down Expand Up @@ -208,6 +214,7 @@
'iconurl' { $body.icon_url = $iconurl}
'iconemoji' { $body.icon_emoji = $iconemoji}
'linknames' { $body.link_names = 1}
'thread' {$body.thread_ts = $Thread}
'Parse' { $body.Parse = $Parse}
'UnfurlLinks' { $body.Unfurl_Links = $UnfurlLinks}
'UnfurlMedia' { $body.Unfurl_Media = $UnfurlMedia}
Expand Down
20 changes: 20 additions & 0 deletions PSSlack/Public/Send-SlackFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
.PARAMETER Channel
Optional channel, private group, or IM channel to send file to. Can be an encoded ID, or a name.

.PARAMETER Thread
Optional thread where file is sent. Needs to be the parent thread id which is either the ts or thread_ts.

Can find a ts by querying https://api.slack.com/methods/conversations.history

.PARAMETER FileName
Required filename for this file. Used to determine syntax highlighting and other functionality.

Expand Down Expand Up @@ -75,6 +80,7 @@
[string]$FileType,

[string[]]$Channel,
[string]$Thread,
[string]$FileName,
[String]$Title,
[String]$Comment,
Expand All @@ -88,6 +94,7 @@
switch ($psboundparameters.keys) {
'Content' {$body.content = $content}
'Channel' {$body.channels = $Channel -join ", " }
'Thread' {$body.thread_ts = $Thread}
'FileName' {$body.filename = $FileName}
'Title' {$body.Title = $Title}
'Comment' {$body.initial_comment = $Comment}
Expand Down Expand Up @@ -137,6 +144,14 @@
$channelContent.Headers.ContentDisposition = $channelHeader
$multipartContent.Add($channelContent)
}
'Thread' {
# Add Thread
$threadHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new('form-data')
$threadHeader.Name = 'thread_ts'
$threadContent = [System.Net.Http.StringContent]::new($Thread)
$threadContent.Headers.ContentDisposition = $threadHeader
$multipartContent.Add($threadContent)
}
'FileName' {
# Add file name
$filenameHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new('form-data')
Expand Down Expand Up @@ -200,6 +215,11 @@
"Content-Disposition: form-data; name=`"channels`"$LF" +
"Content-Type: multipart/form-data$LF$LF" +
($Channel -join ", ") + $LF)}
'Thread' {$bodyLines +=
("--$boundary$LF" +
"Content-Disposition: form-data; name=`"thread_ts`"$LF" +
"Content-Type: multipart/form-data$LF$LF" +
"$Thread$LF")}
'FileName' {$bodyLines +=
("--$boundary$LF" +
"Content-Disposition: form-data; name=`"filename`"$LF" +
Expand Down
10 changes: 10 additions & 0 deletions PSSlack/Public/Send-SlackMessage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function Send-SlackMessage {

See authorship details: https://api.slack.com/methods/chat.postMessage#authorship

.PARAMETER Thread
The id of the parent message you want to thread. This is usually seen as ts or thread_ts in a response.

Can find a ts by querying https://api.slack.com/methods/conversations.history

.PARAMETER IconUrl
URL to an image to use as the icon for this message.

Expand Down Expand Up @@ -264,6 +269,10 @@ function Send-SlackMessage {
ValueFromPipelineByPropertyName = $True)]
$Username,

[parameter(ParameterSetName = 'Param',
ValueFromPipelineByPropertyName = $True)]
$Thread,

[parameter(ParameterSetName = 'Param',
ValueFromPipelineByPropertyName = $True)]
$IconUrl,
Expand Down Expand Up @@ -322,6 +331,7 @@ function Send-SlackMessage {
{
'channel' {$body.channel = $channel }
'text' {$body.text = $text}
'thread' {$body.thread_ts = $Thread}
'username' {$body.username = $username}
'asuser' {$body.as_user = $AsUser}
'iconurl' {$body.icon_url = $iconurl}
Expand Down