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

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

Merged
merged 2 commits into from
Sep 8, 2018
Merged

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

merged 2 commits into from
Sep 8, 2018

Conversation

ChrisLGardner
Copy link

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
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
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
Member

Awesome. Thanks!

@@ -103,15 +103,15 @@ class CommandExecutor : BaseLogger {

# Kick off job and add to job tracker
$cmdExecContext.IsJob = $true
$cmdExecContext.Job = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $true)
Copy link
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'
}

$this.LogDebug("Command [$($cmdExecContext.FullyQualifiedCommandName)] executing in job [$($cmdExecContext.Job.Id)]")
$cmdExecContext.Complete = $false
} else {
# Run command in current session and get results
# This should only be 'builtin' commands
try {
$cmdExecContext.IsJob = $false
$hash = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $false)
$hash = $cmdExecContext.Command.Invoke($cmdExecContext.ParsedCommand, $false,$this._bot.Backend.Name)
Copy link
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.

None yet

2 participants