From 06902c65910aa77b60d5b1ef4397355252913843 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 15 Oct 2019 11:02:51 -0700 Subject: [PATCH 1/7] rtm basics --- .../Private/Invoke-SlackWebAPI.ps1 | 9 +++++- .../Public/rtm/Connect-SlackRtmSession.ps1 | 16 ++++++++++ .../Public/rtm/Start-SlackRtmSession.ps1 | 31 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 Slack/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.ps1 create mode 100644 Slack/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.ps1 diff --git a/Slack/Slack.WebAPI/Private/Invoke-SlackWebAPI.ps1 b/Slack/Slack.WebAPI/Private/Invoke-SlackWebAPI.ps1 index 48658fc..1f49e77 100644 --- a/Slack/Slack.WebAPI/Private/Invoke-SlackWebAPI.ps1 +++ b/Slack/Slack.WebAPI/Private/Invoke-SlackWebAPI.ps1 @@ -7,6 +7,7 @@ function Invoke-SlackWebAPI { $Token, [string] + [ValidateSet('GET','POST')] $REST_Method = 'POST', [string] @@ -26,5 +27,11 @@ function Invoke-SlackWebAPI { Authorization = "Bearer $token" } - Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType -Body ($Body | ConvertTo-NoNullsJson -Depth 100) + if ($Body) { + Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType -Body ($Body | ConvertTo-NoNullsJson -Depth 100) + } + else { + Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType + } + } \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.ps1 b/Slack/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.ps1 new file mode 100644 index 0000000..4cf5494 --- /dev/null +++ b/Slack/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.ps1 @@ -0,0 +1,16 @@ +function Connect-SlackRtmSession { + [CmdletBinding()] + param( + [string] + $token, + + [bool] + $batch_presence_aware, + + [bool] + $presence_sub + ) + + Invoke-SlackWebApi -Token $token -REST_Method 'GET' -Method_Family 'rtm.connect' +} +Set-Alias -Name 'rtm.connect' -Value 'Connect-SlackRtmSession' \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.ps1 b/Slack/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.ps1 new file mode 100644 index 0000000..3346933 --- /dev/null +++ b/Slack/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.ps1 @@ -0,0 +1,31 @@ +function Start-SlackRtmSession { + [CmdletBinding()] + param( + [string] + $token, + + [switch] + $batch_presence_aware, + + [switch] + $include_locale, + + [switch] + $mpim_aware, + + [switch] + $no_latest, + + [bool] + $no_unreads, + + [bool] + $presence_sub, + + [bool] + $simple_latest + ) + + Invoke-SlackWebApi -Token $token -REST_Method 'GET' -Method_Family 'rtm.start' +} +Set-Alias -Name 'rtm.start' -Value 'Start-SlackRtmSession' \ No newline at end of file From 9143c9dc15419954fc65f8dc4addf311c36ca60d Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 15 Oct 2019 11:21:06 -0700 Subject: [PATCH 2/7] initial slack user method --- Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 diff --git a/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 b/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 new file mode 100644 index 0000000..dbff12d --- /dev/null +++ b/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 @@ -0,0 +1,9 @@ +function Get-SlackUsers { + [CmdletBinding()] + param( + [string] + $Token + ) + + Invoke-SlackWebAPI -Token $Token -Method_Family "users.list" -REST_Method "GET" +} From a6ea33106446a48822c77bb682e078b0e1f4c054 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sat, 19 Oct 2019 12:59:08 -0700 Subject: [PATCH 3/7] added view methods --- .../Public/users/Get-SlackUsers.ps1 | 1 + .../Public/views/Open-SlackView.ps1 | 21 +++++++++++++ .../Public/views/Push-SlackView.ps1 | 21 +++++++++++++ .../Public/views/Update-SlackView.ps1 | 30 +++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 Slack/Slack.WebAPI/Public/views/Open-SlackView.ps1 create mode 100644 Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 create mode 100644 Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 diff --git a/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 b/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 index dbff12d..e147d0d 100644 --- a/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 +++ b/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 @@ -7,3 +7,4 @@ function Get-SlackUsers { Invoke-SlackWebAPI -Token $Token -Method_Family "users.list" -REST_Method "GET" } +Set-Alias -Name 'users.list' -Value 'Get-SlackUsers' \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Public/views/Open-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Open-SlackView.ps1 new file mode 100644 index 0000000..984b04c --- /dev/null +++ b/Slack/Slack.WebAPI/Public/views/Open-SlackView.ps1 @@ -0,0 +1,21 @@ +function Open-SlackView { + [CmdletBinding()] + param( + [string] + $Token, + + [string] + $trigger_id, + + [Slack.Payloads.View] + $view + ) + + $Body = @{ + trigger_id = $trigger_id + view = $view + } + + Invoke-SlackWebAPI -Token $Token -Method_Family "views.open" -Body $Body +} +Set-Alias -Name 'views.open' -Value 'Open-SlackView' \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 new file mode 100644 index 0000000..fb12338 --- /dev/null +++ b/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 @@ -0,0 +1,21 @@ +function Push-SlackView { + [CmdletBinding()] + param( + [string] + $Token, + + [string] + $trigger_id, + + [Slack.Payloads.View] + $view + ) + + $Body = @{ + trigger_id = $trigger_id + view = $view + } + + Invoke-SlackWebAPI -Token $Token -Method_Family "views.push" -Body $Body +} +Set-Alias -Name 'views.push' -Value 'Push-SlackView' \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 new file mode 100644 index 0000000..5e89f15 --- /dev/null +++ b/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 @@ -0,0 +1,30 @@ +function Update-SlackView { + [CmdletBinding()] + param( + [string] + $Token, + + [Slack.Payloads.View] + $view, + + [string] + [ValidateLength(255)] + $external_id, + + [string] + $hash, + + [string] + $view_id + ) + + $Body = @{ + view = $view + external_id = $external_id + hash = $hash + view_id = $view_id + } + + Invoke-SlackWebAPI -Token $Token -Method_Family "views.update" -Body $Body +} +Set-Alias -Name 'views.update' -Value 'Update-SlackView' \ No newline at end of file From 2b50800318de4a47356d59567a45497a35280e14 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 21 Oct 2019 21:36:22 -0700 Subject: [PATCH 4/7] adding help comments --- .../Classes/Export-BlockKit.Classes.ps1 | 2 +- .../Private/Invoke-SlackWebAPI.ps1 | 21 +++++++--- .../Public/rtm/Connect-SlackRtmSession.ps1 | 20 ++++++++++ .../Public/rtm/Start-SlackRtmSession.ps1 | 33 ++++++++++++++++ .../Public/users/Get-SlackUsers.ps1 | 39 ++++++++++++++++++- .../Public/views/Open-SlackView.ps1 | 18 +++++++++ .../Public/views/Push-SlackView.ps1 | 22 +++++++++++ .../Public/views/Update-SlackView.ps1 | 26 +++++++++++++ .../rtm/Connect-SlackRtmSession.Tests.ps1 | 11 ++++++ .../rtm/Start-SlackRtmSession.Tests.ps1 | 11 ++++++ .../Public/users/Get-SlackUsers.Tests.ps1 | 11 ++++++ .../Public/views/Open-SlackView.Tests.ps1 | 11 ++++++ .../Public/views/Push-SlackView.Tests.ps1 | 11 ++++++ .../Public/views/Update-SlackView.Tests.ps1 | 11 ++++++ 14 files changed, 238 insertions(+), 9 deletions(-) create mode 100644 Tests/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.Tests.ps1 create mode 100644 Tests/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.Tests.ps1 create mode 100644 Tests/Slack.WebAPI/Public/users/Get-SlackUsers.Tests.ps1 create mode 100644 Tests/Slack.WebAPI/Public/views/Open-SlackView.Tests.ps1 create mode 100644 Tests/Slack.WebAPI/Public/views/Push-SlackView.Tests.ps1 create mode 100644 Tests/Slack.WebAPI/Public/views/Update-SlackView.Tests.ps1 diff --git a/Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 b/Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 index d85ce11..15657b9 100644 --- a/Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 +++ b/Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 @@ -3,4 +3,4 @@ $Classes = Get-ChildItem $PSScriptRoot -Recurse -Filter "*.cs" foreach ($class in $Classes) { $Types += (Get-Content $class.FullName -Raw) } -Add-Type -TypeDefinition $Types #-ErrorAction SilentlyContinue \ No newline at end of file +Add-Type -TypeDefinition $Types -ErrorAction SilentlyContinue \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Private/Invoke-SlackWebAPI.ps1 b/Slack/Slack.WebAPI/Private/Invoke-SlackWebAPI.ps1 index 1f49e77..6093533 100644 --- a/Slack/Slack.WebAPI/Private/Invoke-SlackWebAPI.ps1 +++ b/Slack/Slack.WebAPI/Private/Invoke-SlackWebAPI.ps1 @@ -7,7 +7,7 @@ function Invoke-SlackWebAPI { $Token, [string] - [ValidateSet('GET','POST')] + [ValidateSet('GET', 'POST')] $REST_Method = 'POST', [string] @@ -27,11 +27,20 @@ function Invoke-SlackWebAPI { Authorization = "Bearer $token" } - if ($Body) { - Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType -Body ($Body | ConvertTo-NoNullsJson -Depth 100) + if ($ContentType -eq 'application/json;charset=iso-8859-1' ) { + if ($Body) { + Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType -Body ($Body | ConvertTo-NoNullsJson -Depth 100) + } + else { + Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType + } } - else { - Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType + elseif ($ContentType -eq 'application/x-www-form-urlencoded' ) { + if ($Body) { + Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType -Body $Body + } + else { + Invoke-RestMethod -Method $REST_Method -Uri $Uri -Headers $Headers -ContentType $ContentType + } } - } \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.ps1 b/Slack/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.ps1 index 4cf5494..4c6dfab 100644 --- a/Slack/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.ps1 +++ b/Slack/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.ps1 @@ -1,4 +1,24 @@ function Connect-SlackRtmSession { + <# + .SYNOPSIS + Starts a Real Time Messaging Session. + .DESCRIPTION + This function beings a Real Time Messaging Session with Slack + and reserves your application a specific URL with which to connect via websocket. + Unlike rtm.start, this method is focused only on connecting to the RTM API. + .PARAMETER token + A Slack User or Bot token. + .PARAMETER batch_presence_aware + Batch presence deliveries via subscription. Enabling changes the shape of presence_change events. + .PARAMETER presence_sub + Only deliver presence events when requested by subscription. + .LINK + https://api.slack.com/methods/rtm.connect + .EXAMPLE + Connect-SlackRtmSession -token $Token + .EXAMPLE + rtm.connect -token $Token + #> [CmdletBinding()] param( [string] diff --git a/Slack/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.ps1 b/Slack/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.ps1 index 3346933..ae5fce1 100644 --- a/Slack/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.ps1 +++ b/Slack/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.ps1 @@ -1,7 +1,40 @@ function Start-SlackRtmSession { + <# + .SYNOPSIS + Starts a Real Time Messaging session. + .DESCRIPTION + This function begins a Real Time Messaging API session + and reserves your application a specific URL with which to connect via websocket. + It's user-centric and team-centric: your app connects as a specific user or bot user on a specific team. + This method also returns a smorgasbord of data about the team, its channels, and members. + Some times more information than can be provided in a timely or helpful manner. + .PARAMETER token + Authentication token bearing required scopes. + .PARAMETER batch_presence_aware + Batch presence deliveries via subscription. Enabling changes the shape of presence_change events. + .PARAMETER include_locale + Set this to true to receive the locale for users and channels. Defaults to false + .PARAMETER mpim_aware + Returns MPIMs to the client in the API response. + .PARAMETER no_latest + Exclude latest timestamps for channels, groups, mpims, and ims. Automatically sets no_unreads to 1 + .PARAMETER no_unreads + Skip unread counts for each channel (improves performance). + .PARAMETER presence_sub + Only deliver presence events when requested by subscription. + .PARAMETER simple_latest + Return timestamp only for latest message object of each channel (improves performance). + .Link + https://api.slack.com/methods/rtm.start + .EXAMPLE + Start-SlackRtmSession -token $token -no_unreads $true + .EXAMPLE + rtm.start -token $token -include_locale $true + #> [CmdletBinding()] param( [string] + [Parameter(Mandatory = $true)] $token, [switch] diff --git a/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 b/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 index e147d0d..b5422a8 100644 --- a/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 +++ b/Slack/Slack.WebAPI/Public/users/Get-SlackUsers.ps1 @@ -1,10 +1,45 @@ function Get-SlackUsers { + <# + .SYNOPSIS + Lists all users in a Slack team. + .DESCRIPTION + This function returns a list of all users in the Slack workspace. This includes deleted/deactivated users. + .PARAMETER token + Authentication token bearing required scopes. + .PARAMETER cursor + Paginate through collections of data by setting the cursor parameter to a next_cursor attribute + returned by a previous request's response_metadata. + Default value fetches the first "page" of the collection. + .PARAMETER include_locale + Set this to true to receive the locale for users. Defaults to false + .PARAMETER limit + The maximum number of items to return. Fewer than the requested number of items may be returned, + even if the end of the users list hasn't been reached. + .LINK + https://api.slack.com/methods/users.list + .EXAMPLE + Get-SlackUsers -token $token + .EXAMPLE + users.list -token $token -limit 20 + #> [CmdletBinding()] param( [string] - $Token + [Parameter(Mandatory = $true)] + $Token, + + [string] + $cursor, + + [bool] + $include_locale = $false, + + [int] + $limit = 0 ) - Invoke-SlackWebAPI -Token $Token -Method_Family "users.list" -REST_Method "GET" + $Body = "cursor=$cursor&include_local=$include_local&limit=$limit" + + Invoke-SlackWebAPI -Token $Token -Method_Family "users.list" -REST_Method "POST" -Body $Body -ContentType "application/x-www-form-urlencoded" } Set-Alias -Name 'users.list' -Value 'Get-SlackUsers' \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Public/views/Open-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Open-SlackView.ps1 index 984b04c..3caee13 100644 --- a/Slack/Slack.WebAPI/Public/views/Open-SlackView.ps1 +++ b/Slack/Slack.WebAPI/Public/views/Open-SlackView.ps1 @@ -1,4 +1,22 @@ function Open-SlackView { + <# + .SYNOPSIS + Open a view for a user. + .DESCRIPTION + This function opens a modal with a user by exchanging a trigger_id received from another interaction. + .PARAMETER Token + Authentication token bearing required scopes. + .PARAMETER trigger_id + Exchange a trigger to post to the user. + .PARAMETER view + The view payload. Must be of type [Slack.Payloads.View] + .LINK + https://api.slack.com/methods/views.open + .EXAMPLE + Open-SlackView -token $token -tiggerId '12345.98765.abcd2358fdea' -view $view + .EXAMPLE + views.open -token $token -tiggerId '12345.98765.abcd2358fdea' -view $view + #> [CmdletBinding()] param( [string] diff --git a/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 index fb12338..5117e60 100644 --- a/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 +++ b/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 @@ -1,4 +1,26 @@ function Push-SlackView { + <# + .SYNOPSIS + Push a view onto the stack of a root view. + .DESCRIPTION + This function pushes a new view onto the existing view stack + by passing a view payload and a valid trigger_id generated from an interaction within the existing modal. + The pushed view is added to the top of the stack, + so the user will go back to the previous view after they complete or cancel the pushed view. + After a modal is opened, the app is limited to pushing 2 additional views. + .PARAMETER Token + Authentication token bearing required scopes. + .PARAMETER trigger_id + Exchange a trigger to post to the user. + .PARAMETER view + The view payload. Must be of type [Slack.Payloads.View] + .LINK + https://api.slack.com/methods/views.open + .EXAMPLE + Push-SlackView -token $token -tiggerId '12345.98765.abcd2358fdea' -view $view + .EXAMPLE + views.push -token $token -tiggerId '12345.98765.abcd2358fdea' -view $view + #> [CmdletBinding()] param( [string] diff --git a/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 index 5e89f15..b71fd5c 100644 --- a/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 +++ b/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 @@ -1,4 +1,30 @@ function Update-SlackView { + <# + .SYNOPSIS + Update an existing view. + .DESCRIPTION + This function updates a view by passing a new view definition + along with the view_id returned in views.open or the external_id. + .PARAMETER Token + Authentication token bearing required scopes. + .PARAMETER view + The view payload. Must be of type [Slack.Payloads.View] + .PARAMETER external_id + A unique identifier of the view set by the developer. + Must be unique for all views on a team. Max length of 255 characters. + Either view_id or external_id is required. + .PARAMETER hash + A string that represents view state to protect against possible race conditions. + .PARAMETER view_id + A unique identifier of the view to be updated. + Either view_id or external_id is required. + .LINK + https://api.slack.com/methods/views.open + .EXAMPLE + Push-SlackView -token $token -tiggerId '12345.98765.abcd2358fdea' -view $view + .EXAMPLE + views.push -token $token -tiggerId '12345.98765.abcd2358fdea' -view $view + #> [CmdletBinding()] param( [string] diff --git a/Tests/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.Tests.ps1 b/Tests/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.Tests.ps1 new file mode 100644 index 0000000..cc4ce53 --- /dev/null +++ b/Tests/Slack.WebAPI/Public/rtm/Connect-SlackRtmSession.Tests.ps1 @@ -0,0 +1,11 @@ +# If the module is already in memory, remove it +Get-Module Slack | Remove-Module -Force + +# Import the module from the local path, not from the users Documents folder +$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent (Split-Path -Parent ((Split-Path -Parent $MyInvocation.MyCommand.Path))))) +$ModuleRoot = $repoRoot + "\Slack" +Import-Module $ModuleRoot -Force + +InModuleScope -ModuleName Slack { + +} \ No newline at end of file diff --git a/Tests/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.Tests.ps1 b/Tests/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.Tests.ps1 new file mode 100644 index 0000000..cc4ce53 --- /dev/null +++ b/Tests/Slack.WebAPI/Public/rtm/Start-SlackRtmSession.Tests.ps1 @@ -0,0 +1,11 @@ +# If the module is already in memory, remove it +Get-Module Slack | Remove-Module -Force + +# Import the module from the local path, not from the users Documents folder +$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent (Split-Path -Parent ((Split-Path -Parent $MyInvocation.MyCommand.Path))))) +$ModuleRoot = $repoRoot + "\Slack" +Import-Module $ModuleRoot -Force + +InModuleScope -ModuleName Slack { + +} \ No newline at end of file diff --git a/Tests/Slack.WebAPI/Public/users/Get-SlackUsers.Tests.ps1 b/Tests/Slack.WebAPI/Public/users/Get-SlackUsers.Tests.ps1 new file mode 100644 index 0000000..cc4ce53 --- /dev/null +++ b/Tests/Slack.WebAPI/Public/users/Get-SlackUsers.Tests.ps1 @@ -0,0 +1,11 @@ +# If the module is already in memory, remove it +Get-Module Slack | Remove-Module -Force + +# Import the module from the local path, not from the users Documents folder +$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent (Split-Path -Parent ((Split-Path -Parent $MyInvocation.MyCommand.Path))))) +$ModuleRoot = $repoRoot + "\Slack" +Import-Module $ModuleRoot -Force + +InModuleScope -ModuleName Slack { + +} \ No newline at end of file diff --git a/Tests/Slack.WebAPI/Public/views/Open-SlackView.Tests.ps1 b/Tests/Slack.WebAPI/Public/views/Open-SlackView.Tests.ps1 new file mode 100644 index 0000000..cc4ce53 --- /dev/null +++ b/Tests/Slack.WebAPI/Public/views/Open-SlackView.Tests.ps1 @@ -0,0 +1,11 @@ +# If the module is already in memory, remove it +Get-Module Slack | Remove-Module -Force + +# Import the module from the local path, not from the users Documents folder +$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent (Split-Path -Parent ((Split-Path -Parent $MyInvocation.MyCommand.Path))))) +$ModuleRoot = $repoRoot + "\Slack" +Import-Module $ModuleRoot -Force + +InModuleScope -ModuleName Slack { + +} \ No newline at end of file diff --git a/Tests/Slack.WebAPI/Public/views/Push-SlackView.Tests.ps1 b/Tests/Slack.WebAPI/Public/views/Push-SlackView.Tests.ps1 new file mode 100644 index 0000000..cc4ce53 --- /dev/null +++ b/Tests/Slack.WebAPI/Public/views/Push-SlackView.Tests.ps1 @@ -0,0 +1,11 @@ +# If the module is already in memory, remove it +Get-Module Slack | Remove-Module -Force + +# Import the module from the local path, not from the users Documents folder +$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent (Split-Path -Parent ((Split-Path -Parent $MyInvocation.MyCommand.Path))))) +$ModuleRoot = $repoRoot + "\Slack" +Import-Module $ModuleRoot -Force + +InModuleScope -ModuleName Slack { + +} \ No newline at end of file diff --git a/Tests/Slack.WebAPI/Public/views/Update-SlackView.Tests.ps1 b/Tests/Slack.WebAPI/Public/views/Update-SlackView.Tests.ps1 new file mode 100644 index 0000000..cc4ce53 --- /dev/null +++ b/Tests/Slack.WebAPI/Public/views/Update-SlackView.Tests.ps1 @@ -0,0 +1,11 @@ +# If the module is already in memory, remove it +Get-Module Slack | Remove-Module -Force + +# Import the module from the local path, not from the users Documents folder +$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent (Split-Path -Parent ((Split-Path -Parent $MyInvocation.MyCommand.Path))))) +$ModuleRoot = $repoRoot + "\Slack" +Import-Module $ModuleRoot -Force + +InModuleScope -ModuleName Slack { + +} \ No newline at end of file From d5c83e113a5926e5529db206afcfe0051901a68d Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 22 Oct 2019 09:37:46 -0700 Subject: [PATCH 5/7] validatelength requires two arguments. --- Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 | 2 +- Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 | 2 +- Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 b/Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 index 15657b9..d85ce11 100644 --- a/Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 +++ b/Slack/Slack.BlockKit/Classes/Export-BlockKit.Classes.ps1 @@ -3,4 +3,4 @@ $Classes = Get-ChildItem $PSScriptRoot -Recurse -Filter "*.cs" foreach ($class in $Classes) { $Types += (Get-Content $class.FullName -Raw) } -Add-Type -TypeDefinition $Types -ErrorAction SilentlyContinue \ No newline at end of file +Add-Type -TypeDefinition $Types #-ErrorAction SilentlyContinue \ No newline at end of file diff --git a/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 index 5117e60..ede94af 100644 --- a/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 +++ b/Slack/Slack.WebAPI/Public/views/Push-SlackView.ps1 @@ -15,7 +15,7 @@ function Push-SlackView { .PARAMETER view The view payload. Must be of type [Slack.Payloads.View] .LINK - https://api.slack.com/methods/views.open + https://api.slack.com/methods/views.push .EXAMPLE Push-SlackView -token $token -tiggerId '12345.98765.abcd2358fdea' -view $view .EXAMPLE diff --git a/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 index b71fd5c..6a16c75 100644 --- a/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 +++ b/Slack/Slack.WebAPI/Public/views/Update-SlackView.ps1 @@ -33,8 +33,8 @@ function Update-SlackView { [Slack.Payloads.View] $view, + [ValidateLength(0,255)] [string] - [ValidateLength(255)] $external_id, [string] From efd7f16702ab4546a56ab7dded567462a409e386 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 28 Oct 2019 13:57:30 -0700 Subject: [PATCH 6/7] views --- Slack/Slack.BlockKit/Classes/Payloads/Home.cs | 59 +++++++++++++++++++ Slack/Slack.BlockKit/Classes/Payloads/View.cs | 2 +- .../Public/views/Publish-SlackView.ps1 | 45 ++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 Slack/Slack.BlockKit/Classes/Payloads/Home.cs create mode 100644 Slack/Slack.WebAPI/Public/views/Publish-SlackView.ps1 diff --git a/Slack/Slack.BlockKit/Classes/Payloads/Home.cs b/Slack/Slack.BlockKit/Classes/Payloads/Home.cs new file mode 100644 index 0000000..31891b9 --- /dev/null +++ b/Slack/Slack.BlockKit/Classes/Payloads/Home.cs @@ -0,0 +1,59 @@ +namespace Slack +{ + namespace Payloads + { + using Slack.Composition; + using Slack.Layout; + public class Home : View + { + private Block[] _blocks; + private const int maxBlocks = 100; + private string _private_metadata; + private const int private_metadataLength = 3000; + private string _callback_id; + private const int callback_idLength = 255; + public string external_id; + + public Home(Block[] blocks) : base("home") + { + this.blocks = blocks; + } + + public Block[] blocks + { + get => _blocks; set + { + if (value.Length > maxBlocks) + { + throw new System.Exception($"Modals can only have up to {maxBlocks} blocks."); + } + _blocks = value; + } + } + + public string private_metadata + { + get => _private_metadata; set + { + if (value.Length > private_metadataLength) + { + throw new System.Exception($"private_metadata length must be less than {private_metadataLength} characters."); + } + _private_metadata = value; + } + } + + public string callback_id + { + get => _callback_id; set + { + if (value.Length > callback_idLength) + { + throw new System.Exception($"callback_id length must be less than {callback_idLength} characters."); + } + _callback_id = value; + } + } + } + } +} \ No newline at end of file diff --git a/Slack/Slack.BlockKit/Classes/Payloads/View.cs b/Slack/Slack.BlockKit/Classes/Payloads/View.cs index cd3cc06..b9bb4f8 100644 --- a/Slack/Slack.BlockKit/Classes/Payloads/View.cs +++ b/Slack/Slack.BlockKit/Classes/Payloads/View.cs @@ -5,7 +5,7 @@ namespace Payloads public abstract class View { public string type; - private readonly string[] viewTypes = { "modal" }; + private readonly string[] viewTypes = { "modal", "home" }; public View(string type) { diff --git a/Slack/Slack.WebAPI/Public/views/Publish-SlackView.ps1 b/Slack/Slack.WebAPI/Public/views/Publish-SlackView.ps1 new file mode 100644 index 0000000..7d3bc12 --- /dev/null +++ b/Slack/Slack.WebAPI/Public/views/Publish-SlackView.ps1 @@ -0,0 +1,45 @@ +function Publish-SlackView { + <# + .SYNOPSIS + Publish a static view for a User. + .DESCRIPTION + This function creates or updates the view that comprises an app's Home tab for a specific user. + .PARAMETER Token + Authentication token bearing required scopes. + .PARAMETER user_id + id of the user you want publish a view to. + .PARAMETER view + The view payload. Must be of type [Slack.Payloads.View] + .PARAMETER hash + A string that represents view state to protect against possible race conditions. + .LINK + https://api.slack.com/methods/views.publish + .EXAMPLE + Publish-SlackView -token $token -view $view + .EXAMPLE + views.publish -token $token -view $view + #> + [CmdletBinding()] + param( + [string] + $Token, + + [string] + $user_id, + + [Slack.Payloads.View] + $view, + + [string] + $hash + ) + + $Body = [PSCustomObject]@{ + user_id = $user_id + view = $view + hash = $hash + } + + Invoke-SlackWebAPI -Token $Token -Method_Family "views.publish" -Body $Body +} +Set-Alias -Name 'views.publish' -Value 'Publish-SlackView' \ No newline at end of file From 63f33b90f6c1e7f5e5bf23e64dac8ba75452edcf Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 29 Oct 2019 12:14:59 -0700 Subject: [PATCH 7/7] publish view test file --- .../Public/views/Publish-SlackView.Tests.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Tests/Slack.WebAPI/Public/views/Publish-SlackView.Tests.ps1 diff --git a/Tests/Slack.WebAPI/Public/views/Publish-SlackView.Tests.ps1 b/Tests/Slack.WebAPI/Public/views/Publish-SlackView.Tests.ps1 new file mode 100644 index 0000000..cc4ce53 --- /dev/null +++ b/Tests/Slack.WebAPI/Public/views/Publish-SlackView.Tests.ps1 @@ -0,0 +1,11 @@ +# If the module is already in memory, remove it +Get-Module Slack | Remove-Module -Force + +# Import the module from the local path, not from the users Documents folder +$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent (Split-Path -Parent ((Split-Path -Parent $MyInvocation.MyCommand.Path))))) +$ModuleRoot = $repoRoot + "\Slack" +Import-Module $ModuleRoot -Force + +InModuleScope -ModuleName Slack { + +} \ No newline at end of file