-
Notifications
You must be signed in to change notification settings - Fork 4
/
SendTo-Campfire.ps1
46 lines (40 loc) · 1.48 KB
/
SendTo-Campfire.ps1
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
<#
Usage:
$Env:CAMPFIRE_DEFAULT_ROOMNUMBER="123456"
$Env:CAMPFIRE_TOKEN="abcdef1234567890...."
$Env:CAMPFIRE_SUBDOMAIN="yoursubdomain"
"rimshot" | SendTo-Campfire.ps1 -PlaySound
SendTo-Campfire.ps1 "trombone" -PlaySound
SendTo-Campfire.ps1 "say hello"
#>
param (
[parameter(mandatory=$true,valuefrompipeline=$true)]
[string]$Body,
[switch]$PlaySound,
[string]$RoomNumber = $Env:CAMPFIRE_DEFAULT_ROOMNUMBER,
[string]$AuthToken = $Env:CAMPFIRE_TOKEN,
[string]$SubDomain = $Env:CAMPFIRE_SUBDOMAIN
)
if( !$AuthToken ) {
throw "Auth token is missing. Set parameter explicitly or give `$Env:CAMPFIRE_TOKEN a value"
}
if( !$SubDomain ) {
throw "Sub domain is missing. Set parameter explicitly or give `$Env:CAMPFIRE_SUBDOMAIN a value"
}
if( !$RoomNumber ) {
throw "Room number is missing. Set parameter explicitly or give `$Env:CAMPFIRE_DEFAULT_ROOMNUMBER a value"
}
$postUrl = "https://{0}.campfirenow.com/room/{1}/speak.json" -f $SubDomain, $RoomNumber
$msg = @{ body = $Body }
if( $PlaySound ) {
$msg.type = "SoundMessage"
}
$result = @{ message = $msg } | convertto-json -compress | curl -i -u "${AuthToken}:X" -H 'Content-Type: application/json' -d `@- $postUrl 2>&1
if ( !($result | ?{ $_ -match "Created$" }) ) {
Write-Host "Error posting message to Campfire" -foregroundcolor red
}
elseif( $PlaySound ) {
Write-Host "Played sound '$Body' in room $RoomNumber on Campfire" -foregroundcolor green
} else {
Write-Host "Posted message '$Body' to room $RoomNumber on Campfire" -foregroundcolor green
}