Public/Get-SlackWebChannelMessages.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
function Get-SlackWebChannelMessages {
    Param (
        [Parameter(Mandatory)]
        [string]$ChannelID,
        [Parameter(DontShow)]
        [string]$cursor
    )

    $GetChannelMessagesPagedParameters = @{
        ChannelID = $ChannelID
    }

    if ($cursor) {
        $GetChannelMessagesPagedParameters.Add('cursor', $cursor)
    }

    $Response = Get-ChannelMessagesPaged @GetChannelMessagesPagedParameters
    $ResponseProcessed = $Response.Content | ConvertFrom-Json
    $ResponseProcessed.messages

    if ($ResponseProcessed.response_metadata.next_cursor) {
        Get-SlackWebChannelMessages -ChannelID $ChannelID -cursor $ResponseProcessed.response_metadata.next_cursor
    }
}