Public/New-PSlickPSlackConfig.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function New-PSlickPSlackConfig {
    <#
    .SYNOPSIS
        Creates a new PSlickPSlack config file
    .DESCRIPTION
        This function will create a local configuration file that stores user-specific information like their Slack Workspace token or webhook.
    .PARAMETER botToken
        A Slack Bot token
    .PARAMETER userToken
        A Slack User token
    .PARAMETER defaultChannel
        The name or ID of a default channel to use for output.
    .EXAMPLE
        New-PSlickPSlackConfig -botToken "xxxx-xxxx-xxxx-xxxx"
    #>

    [CmdletBinding()]
    param(
        [string]
        [ValidateScript({$_ -match "^xoxb-"})]
        $botToken,

        [string]
        [ValidateScript({$_ -match "^xoxp-"})]
        $userToken,

        [string]
        $defaultChannel
    )

    $root = (Get-Item $PSScriptRoot).Parent.FullName

    $value = @"
{
    "botToken":"$botToken",
    "userToken":"$userToken",
    "defaultChannel":"$defaultChannel"
}
"@


    New-Item -Path $root -Name "pslickpslackconfig.json" -ItemType File -Value $value -Force
}