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

PSSlack threaded responses #232

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions PoshBot/Implementations/Slack/SlackBackend.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -420,7 +425,7 @@ class SlackBackend : Backend {
$attParams.Text = [string]::Empty
}
$att = New-SlackMessageAttachment @attParams
$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)
$msg | Send-SlackMessage -Token $this.Connection.Config.Credential.GetNetworkCredential().Password -Verbose:$false > $null
}
Expand All @@ -436,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
}
Expand All @@ -447,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)) {
Expand All @@ -463,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
Expand All @@ -477,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)) {
Expand All @@ -490,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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PoshBot/PoshBot.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +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'}
@{ModuleName = 'PSSlack'; ModuleVersion = '1.0.2'}
@{ModuleName = 'PSSlack'; ModuleVersion = '1.0.6'}
)

# Assemblies that must be loaded prior to importing this module
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Want some in-depth guides? Check out [ChatOps the Easy Way](https://leanpub.com/
</a>
</p>


# Introduction

PoshBot is a chat bot written in [PowerShell](https://msdn.microsoft.com/powershell).
Expand Down
2 changes: 1 addition & 1 deletion docker/alpine3.8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/nano/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/ubuntu16.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/ubuntu18.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/windowsservercore/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}