Skip to content
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 2 commits into from
Mar 28, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions HipChatPS/Public/Send-HipChat.ps1
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])]
Expand All @@ -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)]
Copy link
Collaborator

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'.

Copy link
Member

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.

Copy link
Collaborator

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.

Copy link
Member

@lipkau lipkau Apr 4, 2018

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it

Copy link
Collaborator

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 :)

[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,

Expand All @@ -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)

Expand Down