Pass the backend type into a Command -fixes #104#105
Pass the backend type into a Command -fixes #104#105devblackops merged 2 commits intoposhbotio:masterfrom ChrisLGardner:add-backend-context
Conversation
Some systems like Teams will not automatically expand some output, like image links so sending them markdown instead of a plain link will correct this to enable this behaviour we need to be able to let other plugins know which backend it is talking to. Using $Global:PoshbotContext.BackendType will enable this.
|
Made a quick fix to tidy up the casing on _bot and add .Name since I'd missed it from one of the Invoke calls. |
|
@ChrisLGardner I think this should be |
|
Awesome. Thanks! |
|
|
||
| # Kick off job and add to job tracker | ||
| $cmdExecContext.IsJob = $true | ||
| $cmdExecContext.Job = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $true) |
There was a problem hiding this comment.
I think this should be $this._Bot.Backend.GetType().Name (which will always return SlackBackend or TeamsBackend for the builtin backends. Relying on $this._bot.Backend.Name will prove inconsistent because that value is settable by the user when they create an instance of a backend and can be whatever value they want. See below:
$backend = New-PoshBotSlackBackend -Configuration @{
Name = 'MyAwesomeSlackBackend'
Token = 'SUPER SECRET'
}
PoshBot/Classes/CommandExecutor.ps1
Outdated
| try { | ||
| $cmdExecContext.IsJob = $false | ||
| $hash = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $false) | ||
| $hash = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $false,$this._bot.Backend.Name) |
Description
Some systems like Teams will not automatically expand some output, like image links so sending them markdown instead of a plain link will correct this to enable this behaviour we need to be able to let other plugins know which backend it is talking to. Using $Global:PoshbotContext.BackendType will enable this.
I used the name of the backend as I didn't want to pass the whole Backend in when it wasn't really needed.
Related Issue
#104
How Has This Been Tested?
Tested with the xkcd plugin and using this code. Built locally and tested with Teams. I don't have a slack workspace to test it with but I can't see why it won't work. I'll submit a PR to PoshBot.xkcd as well with this fix.
Types of changes
Checklist: