Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Enable rich (html) messages #66

Closed
apsoto opened this issue Oct 28, 2014 · 11 comments
Closed

Enable rich (html) messages #66

apsoto opened this issue Oct 28, 2014 · 11 comments

Comments

@apsoto
Copy link

apsoto commented Oct 28, 2014

sparked from the conversation at litaio/lita-hipchat#7.

To allow plugins to provide adapter specific rich formatted messages we can borrow the Rails pattern for view templates.

The plugin can provide templates that follow the pattern: HANDLER.ROUTE.ADAPTER.erb, where:

HANDLER = registered handler class name
ROUTE = the method symbol passed to #route
ADAPTER = the adapter name (hipchat, slack, shell, etc)

For example, the lita-jira plugin can provide hipchat and slack specific templates like so:

jira.issue_details.hipchat.erb
jira.issue_details.slack.erb

If the argument sent to Response#reply is a hash, it's the context variables to use in a template, otherwise fall back to old behavior which is a text message

If the adapter being used doesn't have a template, then the hash should provide a fallback message string which would be the same message string that's passed now.

This would allow plugin authors to provide rich response templates, but existing ones continue to work sending plain text.

@jimmycuadra
Copy link
Collaborator

Very interesting idea. Would you be interested in prototyping it as a plugin?

@apsoto
Copy link
Author

apsoto commented Oct 30, 2014

pretty swamped right now so can't estimate when I'd get to it, but I'll put it on my todo list.

@jimmycuadra
Copy link
Collaborator

This is released in Lita 4.2! Thanks for helping figure out how to get this feature in!

http://docs.lita.io/plugin-authoring/handlers/#templates

@apsoto
Copy link
Author

apsoto commented Jan 30, 2015

great, can't wait to try it out.

@dieterdemeyer
Copy link

I'm trying this out using the slack adapter but can't seem to get this working..
Should it now be possible to handle for example bold text, bullet points and href elements in an ERB template ?
I'm not really sure what I'm doing wrong with my example:

<b><%= @members.length %></b> members in GitHub Team <b><%= @team %></b><br>
<% @members.each do |member| %>
&bull; <%= member %><br>
<% end %>

Any tips would be appreciated...

@jimmycuadra
Copy link
Collaborator

Slack doesn't use HTML in messages, it uses a Markdown-style format: https://slack.zendesk.com/hc/en-us/articles/202288908-Formatting-your-messages

@dieterdemeyer
Copy link

I feel quite stupid now...
I tried it and this works for most items, except the URL handling...
I'm using the following code in my .erb file:

*GitHub Org Pull Requests:*
<% @github_open_issues.each do |repo_name, issues| %>
<% issues.each do |issue| %>
• <%= repo_name %>: <<%= issue.html_url %>|pull request #<%= issue.number %>> - <%= issue.title %> - by <<%= issue.user.html_url %>|<%= issue.user.login %>>
<% end %>
<% end %>

Any suggestions on what I'm doing wrong ?

@jimmycuadra
Copy link
Collaborator

What is the expected output and what are you seeing instead?

@dieterdemeyer
Copy link

The output now is:

• puppet-alternatives: <https://github.com/cegeka/puppet-alternatives/pull/1|pull request #1> - fix: insync function comparing current and should items - by <https://github.com/vladnazarenko|vladnazarenko>

But I would like to see the following:

• puppet-alternatives: pull request #1 - fix: insync function comparing current and should items - by vladnazarenko

I think I'm using the correct syntax for links in Slack but any help would be appreciated.

@jimmycuadra
Copy link
Collaborator

Would you mind opening a separate issue on lita-slack? I don't wanna lose track of this!

@dieterdemeyer
Copy link

No problem.
Issue submitted at litaio/lita-slack#36

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

No branches or pull requests

3 participants