Public/MessageLayoutBlocks/New-SlackContextBlock.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
function New-SlackContextBlock {
    <#
    .SYNOPSIS
        Returns a Slack Context Block.
    .DESCRIPTION
        This function returns a Slack Context Block as a PSCustom Object ready to ConvertTo-Json and send to Slack.
    .PARAMETER elements
        An array of image elements and text objects.
    .PARAMETER block_id
        Specifies the block_id of the Slack Block for reference by the Slack APIs.
    .LINK
        https://api.slack.com/reference/messaging/blocks#context
    .EXAMPLE
        New-SlackContextBlock -elements $elements -block_id "block44"
    #>

    [Cmdletbinding()]
    param(
        [Parameter(Mandatory)]
        [ValidateCount(1,10)]
        [pscustomobject[]]
        $elements,

        [string]
        [ValidateLength(1,255)]
        $block_id
    )

    $SlackContextBlock = [pscustomobject]@{
        type = "context"
        elements = $elements
    }
    if($block_id){
        $SlackContextBlock | Add-Member -NotePropertyName "block_id" -NotePropertyValue $block_id
    }

    return $SlackContextBlock
}