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

PushoverAgent: HTML message support #2264

Merged
merged 3 commits into from
Apr 21, 2018
Merged
Changes from all commits
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
12 changes: 12 additions & 0 deletions app/models/agents/pushover_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PushoverAgent < Agent
* `sound` - the name of one of the sounds supported by device clients to override the user's default sound choice. [See PushOver docs for sound options.](https://pushover.net/api#sounds)
* `retry` - Required for emergency priority - Specifies how often (in seconds) the Pushover servers will send the same notification to the user. Minimum value: `30`
* `expire` - Required for emergency priority - Specifies how many seconds your notification will continue to be retried for (every retry seconds). Maximum value: `86400`
* `html` - set to `true` to have Pushover's apps display the `message` content as HTML

MD

Expand All @@ -47,6 +48,7 @@ def default_options
'sound' => '{{ sound }}',
'retry' => '{{ retry }}',
'expire' => '{{ expire }}',
'html' => 'false',
'expected_receive_period_in_days' => '1'
}
end
Expand Down Expand Up @@ -95,6 +97,16 @@ def receive(incoming_events)
post_params[key] = value
end
end
# html is special because String.try_convert(true) gives nil (not even "nil", just nil)
if value = interpolated['html'].presence
post_params['html'] =
case value.to_s
when 'true', '1'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why we want to support 1 as true here? We normally rely on the boolify that only accepts true and "true".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushover's API documentation gives 1 as the value to pass, so it made sense to support what their docs said to do.

'1'
else
'0'
end
end

send_notification(post_params)
end
Expand Down