-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from mgeorgebrown89/rtm
Rtm
- Loading branch information
Showing
17 changed files
with
482 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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] | ||
$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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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] | ||
$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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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] | ||
[Parameter(Mandatory = $true)] | ||
$Token, | ||
|
||
[string] | ||
$cursor, | ||
|
||
[bool] | ||
$include_locale = $false, | ||
|
||
[int] | ||
$limit = 0 | ||
) | ||
|
||
$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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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] | ||
$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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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.push | ||
.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] | ||
$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' |
Oops, something went wrong.