Skip to content

Commit

Permalink
Merge pull request #90 from devblackops/page-channels and !Deploy
Browse files Browse the repository at this point in the history
Add paging support to Get-SlackChannel
  • Loading branch information
RamblingCookieMonster authored Jun 7, 2019
2 parents b2697c1 + 1793e41 commit 326c123
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions PSSlack/Public/Get-SlackChannel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
.PARAMETER Raw
If specified, we provide raw output and do not parse any responses
.PARAMETER Paging
If specified, and more data is available when a paging cursor is returned, continue querying Slack until
we have retrieved all the data available.
.PARAMETER MaxQueries
Limit the count of API queries to this number. Only used if you enable -Paging
.FUNCTIONALITY
Slack
#>
Expand All @@ -34,12 +41,16 @@
[ValidateSet('public_channel', 'private_channel', 'mpim', 'im')]
[string[]]$Types,
[switch]$ExcludeArchived,
[switch]$Raw
[switch]$Raw,
[switch]$Paging,
[int]$MaxQueries
)
end
{
Write-Verbose "$($PSBoundParameters | Remove-SensitiveData | Out-String)"
$body = @{}
$body = @{
limit = 200
}
if ($ExcludeArchived)
{
$body.Add("exclude_archived",1)
Expand All @@ -57,13 +68,33 @@
{
$body.add("types","public_channel,private_channel")
}

$params = @{
Body = $body
Token = $Token
Method = 'conversations.list'
}
$RawChannels = Send-SlackApi @params

$RawChannels = @()
$has_more = $false
$Queries = 0
do {
$params = @{
Body = $body
Token = $Token
Method = 'conversations.list'
}
$response = Send-SlackApi @params
$Queries++
if (-not [string]::IsNullOrEmpty($response.response_metadata.next_cursor))
{
$has_more = $true
$body['cursor'] = $response.response_metadata.next_cursor
}
else
{
$has_more = $false
}
$RawChannels += $response
} until (
-not $Paging -or
-not $has_more -or
($MaxQueries -and $Queries -ge $MaxQueries)
)

$HasWildCard = $False
foreach($Item in $Name)
Expand Down

0 comments on commit 326c123

Please sign in to comment.