{"id":13529334,"url":"https://github.com/RamblingCookieMonster/PSSlack","last_synced_at":"2025-04-01T15:30:48.989Z","repository":{"id":45106041,"uuid":"58669505","full_name":"RamblingCookieMonster/PSSlack","owner":"RamblingCookieMonster","description":"PowerShell module for simple Slack integration","archived":false,"fork":false,"pushed_at":"2022-12-01T17:58:38.000Z","size":421,"stargazers_count":273,"open_issues_count":46,"forks_count":73,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-03-30T06:11:08.788Z","etag":null,"topics":["notifications","powershell","powershell-modules","slack","slack-sender"],"latest_commit_sha":null,"homepage":"http://ramblingcookiemonster.github.io/PSSlack/","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RamblingCookieMonster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["ramblingcookiemonster"]}},"created_at":"2016-05-12T19:09:30.000Z","updated_at":"2025-01-15T05:12:08.000Z","dependencies_parsed_at":"2023-01-22T11:30:36.087Z","dependency_job_id":null,"html_url":"https://github.com/RamblingCookieMonster/PSSlack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RamblingCookieMonster%2FPSSlack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RamblingCookieMonster%2FPSSlack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RamblingCookieMonster%2FPSSlack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RamblingCookieMonster%2FPSSlack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RamblingCookieMonster","download_url":"https://codeload.github.com/RamblingCookieMonster/PSSlack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246662269,"owners_count":20813720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["notifications","powershell","powershell-modules","slack","slack-sender"],"created_at":"2024-08-01T07:00:35.473Z","updated_at":"2025-04-01T15:30:48.966Z","avatar_url":"https://github.com/RamblingCookieMonster.png","language":"PowerShell","funding_links":["https://github.com/sponsors/ramblingcookiemonster"],"categories":["API Wrapper","🚀 Productivity",":hammer_and_wrench: \u0026nbsp; Libraries and SDKs","PowerShell"],"sub_categories":["PowerShell"],"readme":"[![Build status](https://ci.appveyor.com/api/projects/status/kuxiy9m0g19g04o0?svg=true)](https://ci.appveyor.com/project/RamblingCookieMonster/psslack)\r\n\r\nPSSlack\r\n=============\r\n\r\nThis is a quick and dirty module to interact with the Slack API.\r\n\r\nPull requests and other contributions would be welcome!\r\n\r\n# Instructions\r\n\r\n```powershell\r\n# One time setup\r\n    # Download the repository\r\n    # Unblock the zip\r\n    # Extract the PSSlack folder to a module path (e.g. $env:USERPROFILE\\Documents\\WindowsPowerShell\\Modules\\)\r\n# Or, with PowerShell 5 or later or PowerShellGet:\r\n    Install-Module PSSlack\r\n\r\n# Import the module.\r\n    Import-Module PSSlack    #Alternatively, Import-Module \\\\Path\\To\\PSSlack\r\n\r\n# Get commands in the module\r\n    Get-Command -Module PSSlack\r\n\r\n# Get help\r\n    Get-Help Send-SlackMessage -Full\r\n    Get-Help about_PSSlack\r\n```\r\n\r\n### Prerequisites\r\n\r\n* PowerShell 3 or later\r\n* A valid token or incoming webhook uri from Slack.\r\n  * [Grab a test token](https://api.slack.com/docs/oauth-test-tokens)\r\n  * [Register a Slack app, grab a token](https://api.slack.com/docs/oauth) - we'll try wrapping this in the module later\r\n  * [Add an incoming webhook to your team, grab the Uri](https://my.slack.com/services/new/incoming-webhook/)\r\n\r\n# Examples\r\n\r\n### Send a Simple Slack Message\r\n\r\n```powershell\r\n# This example shows a crudely crafted message without any attachments,\r\n# using parameters from Send-SlackMessage to construct the message.\r\n\r\n#Previously set up Uri from https://\u003cYOUR TEAM\u003e.slack.com/apps/A0F7XDUAZ\r\n$Uri = \"Some incoming webhook uri from Slack\"\r\n\r\nSend-SlackMessage -Uri $Uri `\r\n                  -Channel '@wframe' `\r\n                  -Parse full `\r\n                  -Text 'Hello @wframe, join me in #devnull!'\r\n\r\n# Send a message to @wframe (not a channel), parsing the text to linkify usernames and channels\r\n```\r\n\r\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![Simple Send-SlackMessage](/Media/SimpleMessage.png)\r\n\r\n### Search for a Slack Message\r\n\r\n```powershell\r\n# Search for a message containing PowerShell, sorting results by timestamp\r\n\r\nFind-SlackMessage -Token $Token `\r\n                  -Query 'PowerShell' `\r\n                  -SortBy timestamp\r\n```\r\n\r\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![Find Message](/Media/FindMessage.png)\r\n\r\n```powershell\r\n# Search for a message containing PowerShell\r\n# Results are sorted by best match by default\r\n# Notice the extra properties and previous/next messages\r\n\r\nFind-SlackMessage -Token $Token `\r\n                  -Query 'PowerShell' |\r\n    Select-Object -Property *\r\n```\r\n\r\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![Find Message Select All](/Media/FindMessageSelect.png)\r\n\r\nYou could use this simply to search Slack from the CLI, or in an automated solution that might avoid posting if certain content is already found in Slack.\r\n\r\n### Send a Richer Slack Message\r\n\r\n```powershell\r\n# This is a simple example illustrating some common options\r\n# when constructing a message attachment\r\n# giving you a richer message\r\n\r\n$Token = 'A token. maybe from https://api.slack.com/docs/oauth-test-tokens'\r\n\r\nNew-SlackMessageAttachment -Color $([System.Drawing.Color]::red) `\r\n                           -Title 'The System Is Down' `\r\n                           -TitleLink https://www.youtube.com/watch?v=TmpRs7xN06Q `\r\n                           -Text 'Please Do The Needful' `\r\n                           -Pretext 'Everything is broken' `\r\n                           -AuthorName 'SCOM Bot' `\r\n                           -AuthorIcon 'http://ramblingcookiemonster.github.io/images/tools/wrench.png' `\r\n                           -Fallback 'Your client is bad' |\r\n    New-SlackMessage -Channel '@wframe' `\r\n                     -IconEmoji :bomb: |\r\n    Send-SlackMessage -Token $Token\r\n```\r\n\r\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![Rich messages](/Media/RichMessage.png)\r\n\r\nNotice that the title is clickable.  You might link to...\r\n\r\n* The alert in question\r\n* A logging solution query\r\n* A dashboard\r\n* Some other contextual link\r\n* Strongbad\r\n\r\n### Send Multiple Slack Attachments\r\n\r\n```powershell\r\n# This example demonstrates that you can chain new attachments\r\n# together to form a multi-attachment message\r\n\r\n$Token = 'A token. maybe from https://api.slack.com/docs/oauth-test-tokens'\r\n\r\nNew-SlackMessageAttachment -Color $_PSSlackColorMap.red `\r\n                           -Title 'The System Is Down' `\r\n                           -TitleLink https://www.youtube.com/watch?v=TmpRs7xN06Q `\r\n                           -Text 'Everybody panic!' `\r\n                           -Pretext 'Everything is broken' `\r\n                           -Fallback 'Your client is bad' |\r\n    New-SlackMessageAttachment -Color $([System.Drawing.Color]::Orange) `\r\n                               -Title 'The Other System Is Down' `\r\n                               -TitleLink https://www.youtube.com/watch?v=TmpRs7xN06Q `\r\n                               -Text 'Please Do The Needful' `\r\n                               -Fallback 'Your client is bad' |\r\n    New-SlackMessage -Channel '@wframe' `\r\n                     -IconEmoji :bomb: `\r\n                     -AsUser `\r\n                     -Username 'SCOM Bot' |\r\n    Send-SlackMessage -Token $Token\r\n```\r\n\r\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![Multiple Attachments](/Media/MultiAttachments.png)\r\n\r\nNotice that we can chain multiple New-SlackMessageAttachments together.\r\n\r\n### Send a Table of Key Value Pairs\r\n\r\n```powershell\r\n# This example illustrates a pattern where you might\r\n# want to send output from a script; you might\r\n# include errors, successful items, or other output\r\n\r\n# Pretend we're in a script, and caught an exception of some sort\r\n$Fail = [pscustomobject]@{\r\n    samaccountname = 'bob'\r\n    operation = 'Remove privileges'\r\n    status = \"An error message\"\r\n    timestamp = (Get-Date).ToString()\r\n}\r\n\r\n# Create an array from the properties in our fail object\r\n$Fields = @()\r\nforeach($Prop in $Fail.psobject.Properties.Name)\r\n{\r\n    $Fields += @{\r\n        title = $Prop\r\n        value = $Fail.$Prop\r\n        short = $true\r\n    }\r\n}\r\n\r\n$Token = 'A token. maybe from https://api.slack.com/docs/oauth-test-tokens'\r\n\r\n# Construct and send the message!\r\nNew-SlackMessageAttachment -Color $([System.Drawing.Color]::Orange) `\r\n                           -Title 'Failed to process account' `\r\n                           -Fields $Fields `\r\n                           -Fallback 'Your client is bad' |\r\n    New-SlackMessage -Channel 'devnull' |\r\n    Send-SlackMessage -Uri $uri\r\n\r\n# We build up a pretend error object, and send each property to a 'Fields' array\r\n# Creates an attachment with the fields from our error\r\n# Creates a message fromthat attachment and sents it with a uri\r\n```\r\n\r\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![Fields](/Media/Fields.png)\r\n\r\n### Store and Retrieve Configs\r\n\r\nTo save time and typing, you can save a token or uri to a config file (protected via DPAPI) and a module variable.\r\n\r\nThis is used as the default for commands, and is reloaded if you open a new PowerShell session.\r\n\r\n```powershell\r\n# Save a Uri and Token.\r\n# If both are specified, token takes precedence.\r\nSet-PSSlackConfig -Uri 'SomeSlackUri' -Token 'SomeSlackToken'\r\n\r\n# Read the current cofig\r\nGet-PSSlackConfig\r\n```\r\n\r\n# Notes\r\n\r\nCurrently evaluating .NET Core / Cross-platform functionality.  The following will not work initially:\r\n\r\n* Serialization of URIs and tokens via Set-PSSlackConfig.  Set these values per-session if needed\r\n* [System.Drawing.Color]::SomeColor shortcut.  Use the provided $_PSSlackColorMap hash to simplify this.  E.g. $_PSSlackColorMap.red\r\n\r\nThere are a good number of Slack functions out there, including jgigler's [PowerShell.Slack](https://github.com/jgigler/Powershell.Slack) and Steven Murawski's [Slack](https://github.com/smurawski/Slack).  We borrowed some ideas and code from these - thank you!\r\n\r\nIf you want to go beyond interacting with the Slack API, you might consider [using a bot](http://ramblingcookiemonster.github.io/PoshBot/#references)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRamblingCookieMonster%2FPSSlack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRamblingCookieMonster%2FPSSlack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRamblingCookieMonster%2FPSSlack/lists"}