-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature-send private message to user #9
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
function Send-HipChat { | ||
<# | ||
.SYNOPSIS | ||
Sends messages to a Hipchat room. | ||
Sends messages to a Hipchat room or user. | ||
.DESCRIPTION | ||
Send-HipChat can be used within a script or at the console to send a message to a HipChat room. | ||
Send-HipChat can be used within a script or at the console to send a message to a HipChat room or a private message to a user. | ||
.EXAMPLE | ||
Send-Hipchat -Message 'Hello' -Color 'Green' -Notify -ApiToken myapitoken -Room MyRoom -Retry 5 -RetrySec 10 | ||
|
||
This sends a message of 'Hello' highlighted green in to a room named MyRoom. Users in the room will be notified | ||
in their clients that a new message has been recevied. If it cannot successfully send the message it will retry | ||
5 times, at 10 second intervals. | ||
.EXAMPLE | ||
Send-Hipchat -Message 'Hello' -Server "myserver.hipchat.com" -ApiToken myapitoken -User [email protected] -Retry 5 -RetrySec 10 | ||
|
||
This sends a private message of 'Hello' to a user with an email address of [email protected]. | ||
|
||
#> | ||
[CmdletBinding()] | ||
[OutputType([Boolean])] | ||
|
@@ -25,14 +30,22 @@ | |
#Set whether or not this message should trigger a notification for people in the room. (default: false) | ||
[switch]$notify, | ||
|
||
#Required. Server name, default to 'api.hipchat.com' | ||
[Parameter(Mandatory = $True)] | ||
[string]$server = 'api.hipchat.com', | ||
|
||
#Required. This must be a HipChat API token created by a Room Admin for the room you are sending notifications to. | ||
[Parameter(Mandatory = $True)] | ||
[string]$apitoken, | ||
|
||
#Required. The id or URL encoded name of the HipChat room you want to send the message to. | ||
[Parameter(Mandatory = $True)] | ||
#The id or URL encoded name of the HipChat room you want to send the message to. | ||
[Parameter(Mandatory = $True, ParameterSetName = 'Room')] | ||
[string]$room, | ||
|
||
#The id or URL encoded name of the HipChat room you want to send the message to. | ||
[Parameter(Mandatory = $True, ParameterSetName = 'User')] | ||
[string]$user, | ||
|
||
#The number of times to retry sending the message (default: 0) | ||
[int]$retry = 0, | ||
|
||
|
@@ -46,7 +59,12 @@ | |
"notify" = [string]$notify | ||
} | ||
|
||
$uri = "https://api.hipchat.com/v2/room/$room/notification?auth_token=$apitoken" | ||
switch ($PSCmdlet.ParameterSetName) | ||
{ | ||
"Room"{$uri = "https://api.hipchat.com/v2/room/$room/notification?auth_token=$apitoken"} | ||
"User"{$uri = "https://api.hipchat.com/v2/user/$user/message?auth_token=$apitoken"} | ||
} | ||
|
||
$Body = ConvertTo-Json $messageObj | ||
$Post = [System.Text.Encoding]::UTF8.GetBytes($Body) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't be mandatory = true and have a default. Suggest you remove the 'mandatory = true'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fully agree.
This would normally be tested in the CI; but this is not yet implemented in the project.
I created #12 to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there is CI already on this project, it runs from my AppVeyor account still. The tests are currently failing because
-server
is mandatory and not explicitly declared in the tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok... I meant:
The CI and the tests are not yet aligned with the rest of the projects and the branches to not forbid merging while the CIs do not pass.
sorry for merging without checking the CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, thanks for the clarification :)