4
4
Get history from a Slack group
5
5
6
6
. DESCRIPTION
7
- Get history from a Slack group
7
+ Get history from a Slack group (this is more or less an alias for Get-SlackHistory).
8
8
9
9
. PARAMETER Token
10
10
Specify a token for authorization.
25
25
If specified, include history from the date specified in Before and/or After parameters
26
26
27
27
. PARAMETER Count
28
- Number of messages to return per query. Defaults to 100. Max 1000
28
+ Maximum number of messages to return per query (see 'limit' on API docs) . Defaults to 100. Max 1000
29
29
30
30
. PARAMETER Paging
31
31
If specified, and more data is available with a given 'Count', continue querying Slack until
61
61
)
62
62
begin
63
63
{
64
- function Get-UnixTime {
65
- param ($Date )
66
- $unixEpochStart = new-object DateTime 1970 , 1 , 1 , 0 , 0 , 0 , ([DateTimeKind ]::Utc)
67
- [int ]($Date.ToUniversalTime () - $unixEpochStart ).TotalSeconds
68
- }
69
-
70
64
Write-Verbose " $ ( $PSBoundParameters | Remove-SensitiveData | Out-String ) "
71
-
72
- $body = @ {
73
- channel = $null
74
- count = $count
75
- }
76
- if ($Paging )
77
- {
78
- $PageDirection = ' Backward'
79
- }
80
- $BeforeTS = $null
81
- $AfterTS = $null
82
- if ($PSBoundParameters.ContainsKey (' Before' ))
83
- {
84
- $BeforeTS = Get-UnixTime - Date $Before
85
- $body.add (' latest' , $BeforeTS )
86
- }
87
- if ($PSBoundParameters.ContainsKey (' After' ))
88
- {
89
- $AfterTS = Get-UnixTime - Date $After
90
- $body.add (' oldest' , $AfterTS )
91
- if (-not $PSBoundParameters.ContainsKey (' Before' ) -and $Paging )
92
- {
93
- $PageDirection = ' Forward'
94
- }
95
- }
96
- if ($Inclusive )
97
- {
98
- $body.add (' inclusive' , 1 )
99
- }
100
- $params = @ {
101
- Token = $Token
102
- Method = ' groups.history'
103
- Body = $body
65
+ if ($PSBoundParameters.ContainsKey (' GroupID' )) {
66
+ $PSBoundParameters [' ChannelID' ] = $PSBoundParameters [' GroupID' ]
67
+ $PSBoundParameters.Remove (' GroupID' )
104
68
}
105
- $Queries = 1
106
-
107
69
}
108
- process
109
- {
110
- foreach ($ID in $GroupID )
111
- {
112
- $has_more = $false
113
- $Params.body.channel = $ID
114
- do
115
- {
116
- if ($has_more )
117
- {
118
- if ($Params.Body.oldest )
119
- {
120
- [void ]$Params.Body.remove (' oldest' )
121
- }
122
- if ($Params.Body.latest )
123
- {
124
- [void ]$Params.Body.remove (' latest' )
125
- }
126
- if ($PageDirection -eq ' Forward' )
127
- {
128
-
129
- $ts = $response.messages.ts | Sort-Object |
130
- Microsoft.PowerShell.Utility\Select-Object - last 1
131
- $Params.body.oldest = $ts
132
- Write-Debug " Paging Forward.`n $ (
133
- [pscustomobject ]@ {
134
- After = $After
135
- Before = $Before
136
- LastTS = $response.messages [-1 ].ts
137
- SortLast = $response.messages.ts | Sort-Object |
138
- Microsoft.PowerShell.Utility\Select-Object - last 1
139
- SortFirst = $response.messages.ts | Sort-Object |
140
- Microsoft.PowerShell.Utility\Select-Object - first 1
141
- ts = $ts
142
- } | Out-String
143
- ) "
144
- }
145
- elseif ($PageDirection -eq ' Backward' )
146
- {
147
- $ts = $response.messages [-1 ].ts
148
- if ($AfterTS -and $ts -lt $AfterTS )
149
- {
150
- Write-Debug " TS is less than AfterTS, breaking!"
151
- break
152
- }
153
- $Params.body.latest = $ts
154
- Write-Debug " Paging Forward.`n $ (
155
- [pscustomobject ]@ {
156
- After = $After
157
- Before = $Before
158
- LastTS = $response.messages [-1 ].ts
159
- SortLast = $response.messages.ts | Sort-Object |
160
- Microsoft.PowerShell.Utility\Select-Object - last 1
161
- SortFirst = $response.messages.ts | Sort-Object |
162
- Microsoft.PowerShell.Utility\Select-Object - first 1
163
- ts = $ts
164
- } | Out-String
165
- ) "
166
- }
167
-
168
- $has_more = $false
169
- Write-Debug " Body is now:$ ( $params.body | out-string ) "
170
- }
171
- $response = Send-SlackApi @params
172
-
173
- Write-Debug " $ ( $Response | Format-List - Property * | Out-String ) "
174
-
175
- if ($response.ok )
176
- {
177
-
178
- if ($response.psobject.properties.name -contains ' has_more' -and $response.has_more )
179
- {
180
- Write-Debug ' Paging engaged!'
181
- $has_more = $true
182
- }
183
-
184
- if ($Raw )
185
- {
186
- $link = " $ ( $Script :PSSlack.ArchiveUri ) /$ ( $response.group ) /p$ ( $response.ts -replace ' \.' ) "
187
- $response | Add-Member - MemberType NoteProperty - Name link - Value $link
188
- $response
189
- }
190
- else
191
- {
192
- # Order our messages appropriately according to page direction
193
- if ($Paging -and $PageDirection -eq ' Forward' )
194
- {
195
- Parse- SlackMessage - InputObject $Response | Sort-Object TimeStamp
196
- }
197
- else
198
- {
199
- Parse- SlackMessage - InputObject $Response
200
- }
201
- }
202
- }
203
- else
204
- {
205
- $response
206
- }
207
- $Queries ++
208
- }
209
- until (
210
- -not $Paging -or
211
- -not $has_more -or
212
- ($MaxQueries -and $Queries -gt $MaxQueries )
213
- )
214
- }
70
+ end {
71
+ Get-SlackHistory @PSBoundParameters
215
72
}
216
73
}
0 commit comments