Skip to content

Commit

Permalink
Merge pull request #119 from joshcorr/add-MessageThreading and !Deploy
Browse files Browse the repository at this point in the history
Send a Message/File to a Thread
  • Loading branch information
RamblingCookieMonster authored Jul 1, 2021
2 parents 5057a4b + e41c550 commit 1c9d6c0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
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

0 comments on commit 1c9d6c0

Please sign in to comment.