Skip to content

Pass the backend type into a Command -fixes #104#105

Merged
devblackops merged 2 commits intoposhbotio:masterfrom
ChrisLGardner:add-backend-context
Sep 8, 2018
Merged

Pass the backend type into a Command -fixes #104#105
devblackops merged 2 commits intoposhbotio:masterfrom
ChrisLGardner:add-backend-context

Conversation

@ChrisLGardner
Copy link
Copy Markdown

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.

if ($Global:PoshbotContext.BackendType -eq 'TeamsBackend') {
                    "![img]($($comic.img))"
                }
                else {
                    $Comic.img
                }

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@devblackops devblackops self-requested a review September 6, 2018 04:04
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.
@ChrisLGardner
Copy link
Copy Markdown
Author

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.

@devblackops
Copy link
Copy Markdown
Member

@ChrisLGardner I think this should be $this._Bot.Backend.GetType().Name so it returns the actual class type instead of the arbitrary Name that you can set on the backend. That way, it will be consistent for people who want to use it from the SlackBackend or TeamsBackend backend classes.

@devblackops
Copy link
Copy Markdown
Member

Awesome. Thanks!


# Kick off job and add to job tracker
$cmdExecContext.IsJob = $true
$cmdExecContext.Job = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
}

try {
$cmdExecContext.IsJob = $false
$hash = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $false)
$hash = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $false,$this._bot.Backend.Name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer as above

@devblackops devblackops merged commit 8c1f44d into poshbotio:master Sep 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants