poshbotio / PoshBot

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

Issue with Config not passing params to plugin #183

Closed Riiskyy closed 4 years ago

Riiskyy commented 4 years ago

Hi, I'm running in to this exact issue and I can't figure out why. To start my bot I run the following for the configuration

$params = @{
    Name = 'bot'
    BotAdmins = @('@slackid')
    CommandPrefix = '!'
    LogLevel = 'Info'
    BackendConfiguration = @{
        Name = 'SlackBackend'
        Token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    }
    PluginConfiguration = @{
        SlackBot = @{
            Credential = 'xxxxxxxxxxxxxxxxxxxxx'
            ApiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
            ClientApi = 'https://example.com/json'
            IndexApi = 'https://example1.com/q='
        }
    }
    AlternateCommandPrefixes = @('poshbot')
}

$myBotConfig = New-PoshBotConfiguration @Params

Start-PoshBot -Configuration $myBotConfig

My Params in the .ps1 file is

[PoshBot.BotCommand(
        CommandName = 'search',
        Aliases     = ('s', 'find')
    )]
    [CmdletBinding()]
    param (
        [Parameter(
            Mandatory   = $true,
            HelpMessage = 'Enter your search term.'
        )]
        [string]$Name,

        [Parameter(HelpMessage = 'limit results')]
        [int]$limit,

        [Parameter(Mandatory = $true)]
        [PoshBot.FromConfig('ApiKey')]
        [string]$ApiKey,

        [Parameter(Mandatory = $true)]
        [PoshBot.FromConfig('IndexApi')]
        [string]$IndexApi
    )

PoshBot is also in the required modules in the .psd1, I have tried stopping poshbot and restarting with that configuration. I have tried saving the configuration to a file and loading the config from a file with Save-PoshBotConfiguration and then starting poshbot with that config. I have tried removing and re-installing the plugin. I have removed the poshbot module from my system and deleted the ~/.poshbot folder, this got it working when my commands were in the .psm1 file for a moment but after I set it back to .ps1 files and dotsourcing them in the .psm1 file it stopped again. I tried putting it back but it still wouldn't pass the parameters.

I'm at a loss as from looking over the docs it seems to be correct.

Thanks

Your Environment

devblackops commented 4 years ago

Sorry you're having issues @Riiskyy.

Just to confirm, your plugin (PS module) is called SlackBot correct? The key in PluginConfiguration must match the name of the plugin.

Can you share the exact error you're receiving?

Riiskyy commented 4 years ago

Hi, thanks for the reply. It is the same issue as in https://github.com/poshbotio/PoshBot/issues/147.

CommandRequirementsNotMet: Mandatory parameters for [search] not provided.
Usage:
    syntaxitem
    ----------
    {@{name=search; commonparameters=true; workflowcommonparameters=false; parameter=system.object[]}}

Yes the plugin is named the same as it is in the plugin configuration key i.e locally I can run Get-Command -Module SlackBot and have it return the available commands.

Riiskyy commented 4 years ago

Quick update. I copied over my module to a private server I have instead of doing it from my home machine and it passes the parameter values just fine so seems like a configuration issue on my home machine. I'll try ripping out poshbot and re-installing again later and report back.

devblackops commented 4 years ago

Sounds good @Riiskyy. Let us know if you continue to have issues.

Riiskyy commented 4 years ago

So I have no idea what changed as Idid not change my startup configuration when running on the private server. But when I copied the files back over to my home machine and started teh bot up again the parameters were passed just fine. Very odd, sorry for this waste of time 😃