poshbotio / PoshBot

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

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

Closed ChrisLGardner closed 6 years ago

ChrisLGardner commented 6 years ago

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

Checklist:

ChrisLGardner commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

Awesome. Thanks!