Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

Customize format of messages and message attachments

Open alexweissman opened this issue 10 years ago • 9 comments

I'd like to customize the format for messages that come in through my github webhook integration. Currently, it is possible to customize the content of webhook integrations, using a custom script as described in the documentation.

However, this doesn't give me any control over the layout/format/CSS that gets applied to these messages. For example, to format a Github issue comment notification, I tried the following script:

    return {
      content: {
        attachments: [
            {
                thumb_url: user.avatar_url,
                title: '#' + request.content.issue.number + ' - ' + request.content.issue.title,
                title_link: request.content.comment.html_url,
                text: request.content.comment.body,
                fields: []
            }
        ]
      }
    };

Note the use of thumb_url to grab the commentor's avatar and place it in the message. This produces something like:

screen shot 2016-07-15 at 6 55 34 pm

Note that the title is placed above the thumbnail, rather than aligned to the right above the text. Also, I cannot control the size of the thumbnail. I would like to instead format it to look more like:

screen shot 2016-07-15 at 8 16 35 pm

It would appear that the DOM for message attachments like this is specified in: https://github.com/RocketChat/Rocket.Chat/blob/3c919925964f9b5705e30ecbbfc3ae619ba39d27/packages/rocketchat-message-attachments/client/messageAttachment.html

It would be good to have a way to modify this in production.

Your Rocket.Chat version: 0.35.0

alexweissman avatar Jul 16 '16 00:07 alexweissman

in the text property you can include html and inline css if you wish

geekgonecrazy avatar Oct 27 '16 21:10 geekgonecrazy

Hi,

can you explain how to use html in the text property? "text": '<span>' + request.content.foo + '</span>' prints just the html and replaces the tags with entities.

I've tested it inside and outside the attachment key.

kiamgrebgnur avatar Feb 06 '17 16:02 kiamgrebgnur

@geekgonecrazy Is this still the case? I'm unable to get any custom HTML to render when putting it in the text property.

Sorry for posting in a old issue.

JSzaszvari avatar Aug 01 '17 17:08 JSzaszvari

I too see HTML rendered as text in attachments.text.

antgel avatar Sep 27 '17 14:09 antgel

any resolution for this issue?

valeriucraciun avatar Oct 01 '17 22:10 valeriucraciun

Adding html in message API is not working for me as well: Doing

body = {channel: "aaaaaaaaa", text: "<span>abc</span>"}

spits out <span>abc</span> instead of just the content. Any update on this?

anaida07 avatar Oct 25 '17 05:10 anaida07

I think this is related to some security changes we've made to prevent XSS.

geekgonecrazy avatar Oct 25 '17 20:10 geekgonecrazy

@rodrigok do we intend for that to still work? Or is this no longer supported?

geekgonecrazy avatar Oct 25 '17 20:10 geekgonecrazy

It's no longer supported and we are migrating to use uikit for rich messages.

rodrigok avatar Jan 08 '20 19:01 rodrigok