-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatterPosh.psm1
120 lines (108 loc) · 3.22 KB
/
MatterPosh.psm1
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function Get-MMChannel {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$MMUrl,
[Parameter(Mandatory = $true)]
[string]$ChannelName,
[Parameter(Mandatory = $true)]
[string]$TeamID,
[Parameter(Mandatory = $true)]
[string]$AccessToken
)
$url = "$MMUrl/api/v4/teams/$TeamID/channels/name/$ChannelName"
# your API token here
$headers = @{'Authorization' = 'Bearer ' + $AccessToken}
try {
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
return $response.id
} catch {
Write-Error "Error: $($_.Exception.Message)"
}
}
function Get-MMTeams {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$MMUrl,
[Parameter(Mandatory = $true)]
[string]$AccessToken
)
$url = "$MMUrl/api/v4/teams"
$headers = @{'Authorization' = 'Bearer ' + $AccessToken}
try {
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
return $response
} catch {
Write-Error "Error: $($_.Exception.Message)"
}
}
function Find-MMChannel {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$SearchString,
[Parameter(Mandatory = $true)]
[string]$TeamID,
[Parameter(Mandatory = $true)]
[string]$MMUrl,
[Parameter(Mandatory = $true)]
[string]$AccessToken
)
$url = "$MMUrl/api/v4/teams/$TeamID/channels"
$headers = @{'Authorization' = 'Bearer ' + $AccessToken}
try {
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
return $response | Where-Object { $_.display_name -match $SearchString }
} catch {
Write-Error "Error: $($_.Exception.Message)"
}
}
function Add-MMPost {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$MMUrl,
[Parameter(Mandatory = $true)]
[string]$ChannelId,
[Parameter(Mandatory = $true)]
[string]$AccessToken,
[Parameter(Mandatory = $true)]
[string]$Message,
[Parameter()]
[string]$ThreadId
)
$url = "$MMUrl/api/v4/posts"
$headers = @{'Authorization' = 'Bearer ' + $AccessToken}
$body = @{
channel_id = $ChannelId
message = $Message
root_id = $ThreadId
}
try {
$response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body ($body | ConvertTo-Json)
return $response
} catch {
Write-Error "Error: $($_.Exception.Message)"
}
}
function Remove-MMPost {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$MMUrl,
[Parameter(Mandatory = $true)]
[string]$PostId,
[Parameter(Mandatory = $true)]
[string]$AccessToken
)
$url = "$MMUrl/api/v4/posts/$PostId"
$headers = @{'Authorization' = 'Bearer ' + $AccessToken}
try {
$response = Invoke-RestMethod -Uri $url -Method DELETE -Headers $headers
return $response
} catch {
Write-Error "Error: $($_.Exception.Message)"
}
}
Export-ModuleMember Get-MMChannel, Get-MMTeams, Find-MMChannel, Add-MMPost, Remove-MMPost