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

PushoverAgent: HTML message support #2264

merged 3 commits into from
Apr 21, 2018

Conversation

dgw
Copy link
Contributor

@dgw dgw commented Apr 20, 2018

Pushover has supported displaying the message as HTML in its apps for about three years. https://updates.pushover.net/post/117525190347/html-message-support

Pushover has supported displaying the `message` as HTML in its apps for
about three years. https://updates.pushover.net/post/117525190347/html-message-support
Copy link
Member

@knu knu left a comment

Choose a reason for hiding this comment

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

Nice! I didn't even know Pushover ever supported HTML messages.

@@ -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 `1` to have Pushover's apps display the `message` content as HTML
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be a true/false field, following our conventions.

@@ -84,6 +86,7 @@ def receive(incoming_events)
sound
retry
expire
html
].each do |key|
if value = String.try_convert(interpolated[key].presence)
case key
Copy link
Member

Choose a reason for hiding this comment

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

Add the following lines here to accept true as a value for html:

when 'html'
  case value
  when 'true', '1'
    value = '1'
  else
    next
  end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did mostly this, but explicitly set value = '0' in the else instead of just going to the next key.

@dgw
Copy link
Contributor Author

dgw commented Apr 20, 2018

@knu Addressed your comments, let me know if you want the two commits squashed into one. :)

@knu
Copy link
Member

knu commented Apr 20, 2018

@dgw Great! And yes, please squash them.

@knu
Copy link
Member

knu commented Apr 20, 2018

Oh wait, if html were set to true instead of "true" it would not count. You'd need to treat html separately. For example, outside of the each loop:

if value = interpolated['html'].presence
  post_params['html'] =
    case value.to_s
    when 'true', '1'
      '1'
    else
      '0'
    end
end

@knu
Copy link
Member

knu commented Apr 20, 2018

(That is because String.try_convert(true) == nil.)

For reasons that are not clear, String.try_convert(true) yields nil, not
a string. Go figure.
@dgw
Copy link
Contributor Author

dgw commented Apr 20, 2018

*angry nerd noises*

Now I understand why Gary Bernhardt dropped that line in his "Wat" talk about "languages that suck". 🤣

@knu
Copy link
Member

knu commented Apr 21, 2018

There’s nothing wrong with try_convert, it is meant to work that way. Anyway, thanks for your contribution, I’ll try out HTML messages!

@knu knu merged commit fdf4b07 into huginn:master Apr 21, 2018
@dgw
Copy link
Contributor Author

dgw commented Apr 21, 2018

Ha, I was going to squash at least the first two commits on approval. Oh well.

I don't understand why String.try_convert(true) is meant to return nil for a value that should be easily converted to String, but I'm new to Ruby. Haven't yet gotten my head around the difference between to_s and to_str, the distinction between explicit and implicit conversion, and how try_convert works.

@dgw dgw deleted the pushover_html branch April 21, 2018 05:24
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants