From 06a54e778a4c5498020ff14ccc5bf2fd68e47fc3 Mon Sep 17 00:00:00 2001 From: Joshua Corrick Date: Fri, 25 Jun 2021 21:16:07 -0400 Subject: [PATCH 1/4] Workaround for responding to threads --- PoshBot/Implementations/Slack/SlackBackend.ps1 | 7 ++++++- PoshBot/PoshBot.psd1 | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/PoshBot/Implementations/Slack/SlackBackend.ps1 b/PoshBot/Implementations/Slack/SlackBackend.ps1 index 5e9df7fb..4a3227fd 100644 --- a/PoshBot/Implementations/Slack/SlackBackend.ps1 +++ b/PoshBot/Implementations/Slack/SlackBackend.ps1 @@ -419,8 +419,13 @@ class SlackBackend : Backend { } else { $attParams.Text = [string]::Empty } + #hack for threads + $ThreadSplat = @{} + if ($Response.OriginalMessage.RawMessage.thread_ts){ + $ThreadSplat.Thread = $($Response.OriginalMessage.RawMessage.thread_ts) + } $att = New-SlackMessageAttachment @attParams - $msg = $att | New-SlackMessage -Channel $sendTo -AsUser + $msg = $att | New-SlackMessage -Channel $sendTo -AsUser @ThreadSplat $this.LogDebug("Sending card response back to Slack channel [$sendTo]", $att) $msg | Send-SlackMessage -Token $this.Connection.Config.Credential.GetNetworkCredential().Password -Verbose:$false > $null } diff --git a/PoshBot/PoshBot.psd1 b/PoshBot/PoshBot.psd1 index 0789adeb..35103f78 100644 --- a/PoshBot/PoshBot.psd1 +++ b/PoshBot/PoshBot.psd1 @@ -53,7 +53,8 @@ PowerShellVersion = '5.0' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( @{ModuleName = 'Configuration'; ModuleVersion = '1.3.1'} - @{ModuleName = 'PSSlack'; ModuleVersion = '1.0.2'} + # Requires unpublished version of PSSlack + # @{ModuleName = 'PSSlack'; ModuleVersion = '1.0.2'} ) # Assemblies that must be loaded prior to importing this module From 570832d02842795070ef6767279efe26018c1106 Mon Sep 17 00:00:00 2001 From: Joshua Corrick Date: Sat, 26 Jun 2021 01:45:34 -0400 Subject: [PATCH 2/4] Define threadParam once. --- .../Implementations/Slack/SlackBackend.ps1 | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/PoshBot/Implementations/Slack/SlackBackend.ps1 b/PoshBot/Implementations/Slack/SlackBackend.ps1 index 4a3227fd..d1ef08f7 100644 --- a/PoshBot/Implementations/Slack/SlackBackend.ps1 +++ b/PoshBot/Implementations/Slack/SlackBackend.ps1 @@ -361,6 +361,11 @@ class SlackBackend : Backend { [void]SendMessage([Response]$Response) { # Process any custom responses $this.LogDebug("[$($Response.Data.Count)] custom responses") + # Creating one splat for any messages within a thread + $threadParam = @{} + if ($Response.OriginalMessage.RawMessage.thread_ts){ + $threadParam.Thread = $Response.OriginalMessage.RawMessage.thread_ts + } foreach ($customResponse in $Response.Data) { [string]$sendTo = $Response.To @@ -419,13 +424,8 @@ class SlackBackend : Backend { } else { $attParams.Text = [string]::Empty } - #hack for threads - $ThreadSplat = @{} - if ($Response.OriginalMessage.RawMessage.thread_ts){ - $ThreadSplat.Thread = $($Response.OriginalMessage.RawMessage.thread_ts) - } $att = New-SlackMessageAttachment @attParams - $msg = $att | New-SlackMessage -Channel $sendTo -AsUser @ThreadSplat + $msg = $att | New-SlackMessage -Channel $sendTo -AsUser @threadParam $this.LogDebug("Sending card response back to Slack channel [$sendTo]", $att) $msg | Send-SlackMessage -Token $this.Connection.Config.Credential.GetNetworkCredential().Password -Verbose:$false > $null } @@ -441,7 +441,7 @@ class SlackBackend : Backend { $t = $chunk } $this.LogDebug("Sending text response back to Slack channel [$sendTo]", $t) - Send-SlackMessage -Token $this.Connection.Config.Credential.GetNetworkCredential().Password -Channel $sendTo -Text $t -Verbose:$false -AsUser > $null + Send-SlackMessage -Token $this.Connection.Config.Credential.GetNetworkCredential().Password -Channel $sendTo -Text $t -Verbose:$false -AsUser @threadParam > $null } break } @@ -452,7 +452,6 @@ class SlackBackend : Backend { Token = $this.Connection.Config.Credential.GetNetworkCredential().Password Channel = $sendTo } - if ([string]::IsNullOrEmpty($customResponse.Path) -and (-not [string]::IsNullOrEmpty($customResponse.Content))) { $uploadParams.Content = $customResponse.Content if (-not [string]::IsNullOrEmpty($customResponse.FileType)) { @@ -468,7 +467,7 @@ class SlackBackend : Backend { $this.RemoveReaction($Response.OriginalMessage, [ReactionType]::Success) $this.AddReaction($Response.OriginalMessage, [ReactionType]::Failure) $att = New-SlackMessageAttachment -Color '#FF0000' -Title 'Rut row' -Text "File [$($uploadParams.Path)] not found" -Fallback 'Rut row' - $msg = $att | New-SlackMessage -Channel $sendTo -AsUser + $msg = $att | New-SlackMessage -Channel $sendTo -AsUser @threadParam $this.LogDebug("Sending card response back to Slack channel [$sendTo]", $att) $null = $msg | Send-SlackMessage -Token $this.Connection.Config.Credential.GetNetworkCredential().Password -Verbose:$false break @@ -482,6 +481,11 @@ class SlackBackend : Backend { if (-not [string]::IsNullOrEmpty($customResponse.Title)) { $uploadParams.Title = $customResponse.Title } + #This may not work with other parameters + #Only threaded section that seems to be breaking + if (-not [string]::IsNullOrEmpty($Response.OriginalMessage.RawMessage.thread_ts)) { + $uploadParams.Thread = $Response.OriginalMessage.RawMessage.thread_ts + } Send-SlackFile @uploadParams -Verbose:$false if (-not $customResponse.KeepFile -and -not [string]::IsNullOrEmpty($customResponse.Path)) { @@ -495,7 +499,7 @@ class SlackBackend : Backend { if ($Response.Text.Count -gt 0) { foreach ($t in $Response.Text) { $this.LogDebug("Sending response back to Slack channel [$($Response.To)]", $t) - Send-SlackMessage -Token $this.Connection.Config.Credential.GetNetworkCredential().Password -Channel $Response.To -Text $t -Verbose:$false -AsUser > $null + Send-SlackMessage -Token $this.Connection.Config.Credential.GetNetworkCredential().Password -Channel $Response.To -Text $t -Verbose:$false -AsUser @threadParam > $null } } } From b169eac0798643ce92403cb4d3c522d2d7f65ca8 Mon Sep 17 00:00:00 2001 From: Joshua Corrick Date: Thu, 1 Jul 2021 06:05:04 -0400 Subject: [PATCH 3/4] Bump PSSlack to 1.0.6 --- PoshBot/PoshBot.psd1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PoshBot/PoshBot.psd1 b/PoshBot/PoshBot.psd1 index 35103f78..83517d52 100644 --- a/PoshBot/PoshBot.psd1 +++ b/PoshBot/PoshBot.psd1 @@ -53,8 +53,7 @@ PowerShellVersion = '5.0' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( @{ModuleName = 'Configuration'; ModuleVersion = '1.3.1'} - # Requires unpublished version of PSSlack - # @{ModuleName = 'PSSlack'; ModuleVersion = '1.0.2'} + @{ModuleName = 'PSSlack'; ModuleVersion = '1.0.6'} ) # Assemblies that must be loaded prior to importing this module From 0b05635d9ed56028e379a58db6f0cdc24de03d10 Mon Sep 17 00:00:00 2001 From: Joshua Corrick Date: Mon, 12 Jul 2021 19:53:32 -0400 Subject: [PATCH 4/4] Ensure PSSlack 1.0.6 in all locations --- README.md | 1 - docker/alpine3.8/Dockerfile | 2 +- docker/nano/Dockerfile | 2 +- docker/ubuntu16.04/Dockerfile | 2 +- docker/ubuntu18.04/Dockerfile | 2 +- docker/windowsservercore/Dockerfile | 2 +- requirements.psd1 | 2 +- 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e31b6289..a163721a 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ Want some in-depth guides? Check out [ChatOps the Easy Way](https://leanpub.com/

- # Introduction PoshBot is a chat bot written in [PowerShell](https://msdn.microsoft.com/powershell). diff --git a/docker/alpine3.8/Dockerfile b/docker/alpine3.8/Dockerfile index 20c91128..b02ae612 100644 --- a/docker/alpine3.8/Dockerfile +++ b/docker/alpine3.8/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/powershell:7.0.3-alpine-3.8 as base SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Set-PSRepository -Name PSGallery -InstallationPolicy Trusted; \ Install-Module Configuration -RequiredVersion 1.3.1 -Repository PSGallery -Scope AllUsers -Verbose; \ - Install-Module PSSlack -RequiredVersion 1.0.2 -Repository PSGallery -Scope AllUsers -Verbose; + Install-Module PSSlack -RequiredVersion 1.0.6 -Repository PSGallery -Scope AllUsers -Verbose; FROM base as src ARG version diff --git a/docker/nano/Dockerfile b/docker/nano/Dockerfile index 893b9dd2..8cefc2ec 100644 --- a/docker/nano/Dockerfile +++ b/docker/nano/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/powershell:7.0.3-nanoserver-2004 as base SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $VerbosePreference = 'Continue'; $ProgressPreference = 'SilentlyContinue';"] RUN Set-PSRepository -Name PSGallery -InstallationPolicy Trusted; \ Install-Module Configuration -RequiredVersion 1.3.1 -Repository PSGallery -Scope AllUsers -Verbose; \ - Install-Module PSSlack -RequiredVersion 1.0.2 -Repository PSGallery -Scope AllUsers -Verbose; + Install-Module PSSlack -RequiredVersion 1.0.6 -Repository PSGallery -Scope AllUsers -Verbose; FROM base as src ARG version diff --git a/docker/ubuntu16.04/Dockerfile b/docker/ubuntu16.04/Dockerfile index 9555aa6c..33ad8258 100644 --- a/docker/ubuntu16.04/Dockerfile +++ b/docker/ubuntu16.04/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/powershell:7.0.3-ubuntu-16.04 as base SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Set-PSRepository -Name PSGallery -InstallationPolicy Trusted; \ Install-Module Configuration -RequiredVersion 1.3.1 -Repository PSGallery -Scope AllUsers -Verbose; \ - Install-Module PSSlack -RequiredVersion 1.0.2 -Repository PSGallery -Scope AllUsers -Verbose; + Install-Module PSSlack -RequiredVersion 1.0.6 -Repository PSGallery -Scope AllUsers -Verbose; FROM base as src ARG version diff --git a/docker/ubuntu18.04/Dockerfile b/docker/ubuntu18.04/Dockerfile index 6a0a7e66..21f28e73 100644 --- a/docker/ubuntu18.04/Dockerfile +++ b/docker/ubuntu18.04/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/powershell:7.0.3-ubuntu-18.04 as base SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Set-PSRepository -Name PSGallery -InstallationPolicy Trusted; \ Install-Module Configuration -RequiredVersion 1.3.1 -Repository PSGallery -Scope AllUsers -Verbose; \ - Install-Module PSSlack -RequiredVersion 1.0.2 -Repository PSGallery -Scope AllUsers -Verbose; + Install-Module PSSlack -RequiredVersion 1.0.6 -Repository PSGallery -Scope AllUsers -Verbose; FROM base as src ARG version diff --git a/docker/windowsservercore/Dockerfile b/docker/windowsservercore/Dockerfile index 21a02db5..fc442311 100644 --- a/docker/windowsservercore/Dockerfile +++ b/docker/windowsservercore/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/powershell:7.0.3-windowsservercore-2004 as base SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Set-PSRepository -Name PSGallery -InstallationPolicy Trusted; \ Install-Module Configuration -RequiredVersion 1.3.1 -Repository PSGallery -Scope AllUsers -Verbose; \ - Install-Module PSSlack -RequiredVersion 1.0.2 -Repository PSGallery -Scope AllUsers -Verbose; + Install-Module PSSlack -RequiredVersion 1.0.6 -Repository PSGallery -Scope AllUsers -Verbose; FROM base as src ARG version diff --git a/requirements.psd1 b/requirements.psd1 index 209468ec..54cdce9f 100644 --- a/requirements.psd1 +++ b/requirements.psd1 @@ -7,6 +7,6 @@ Configuration = '1.3.1' Pester = '4.9.0' PSScriptAnalyzer = '1.18.3' - PSSlack = '1.0.2' + PSSlack = '1.0.6' platyPS = '0.14.0' }