poshbotio / PoshBot

Powershell-based bot framework
MIT License
536 stars 108 forks source link

Support for multiple cardresponses in function #199

Open joakimkarlbom opened 4 years ago

joakimkarlbom commented 4 years ago

Expected Behavior

When doing multiple New-PoshBotCardResponse's within a function, the expected outcome should be that it sends the response at the time it is run in the function, and not batched when it has completed.

Current Behavior

Right now, Poshbot will batch all CardResponses until the function either completes or fails.

Possible Solution

This is probably the two places where the logic needs to be changed: I have made some attempts by changing line 167-168 in https://github.com/poshbotio/PoshBot/blob/master/PoshBot/Classes/CommandExecutor.ps1#L162 to

Where-Object {($_.Value.Complete -eq $true) -or
                              ($_.Value.IsJob -and (($_.Value.Job.State -eq 'Completed') -or ($_.Value.Job.State -eq 'Failed')-or ($_.Value.Job.State -eq 'Running')))} |

and commenting out line 476-479 in https://github.com/poshbotio/PoshBot/blob/master/PoshBot/Classes/Bot.ps1#L460 like so:

                       } <# else {
                            $cmdExecContext.Response.Data += New-PoshBotCardResponse -Type Error -Text 'Something bad happened :(' -Title 'Command Error'
                            $cmdExecContext.Response.Data += $cmdExecContext.Result.Errors
                        } #>

Steps to Reproduce (for bugs)

(made by Brandon Olin) function Start-LongRunningCommand { [cmdletbinding()] param( [int]$Count = 5, [int]$DelaySeconds = 2 )

(1..$Count) | % {
    New-PoshBotCardResponse -Text "$_ of $Count...waiting $DelaySeconds seconds"
    Start-Sleep -Seconds $DelaySeconds
}

}

Context

I want more verbose output on each step within more complex functions

Your Environment

devblackops commented 4 years ago

Thanks for the issue @joakimkarlbom. I'll take a look at this when I get a chance to determine if we need to modify more of the code to support this.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.