2

I would like to prepare formatted messages to rocketchat from hubot but I can't find any reference for that.

That's my main reference: http://theprogrammingbutler.com/blog/archives/2011/10/28/hubot-scripts-explained/

I have tried this:

    msg.http(url)
        .headers("PRIVATE-TOKEN": api_key, Accept: 'application/json')
        .get() (err, response, body) ->
            try
                json = JSON.parse(body)

                for issue in json 
                    msg.send "#{issue.title}"
            catch error
                msg.send "Sistema not found."
                console.log(error)

But I would like some more rich and elaborated.

Any sugestion ??

Thanks.

  • Are you attempting to call the rest API from hubot? Or are you using the rocket.chat adapter and trying to send a formatted message? – Aaron Ogle Jul 23 '17 at 06:49
  • Hi Aaron, I'm using rocket.chat adapter and trying to send a formatted message. The formatted messages in Slack bots are very rich in experience and I would like to do the same with Rocket. Regards. – Jose Ricardo Xavier Jul 31 '17 at 13:38

2 Answers2

4

The hubot adapter for Rocket.Chat has a method called customMessage. You can include attachments like you would with slack to achieve rich messages.

To use customMessage use something like this:

robot.adapter.customMessage({
  channel: room,
  attachments: [
    {
       title: "New Event",
       title_link: "http://example.com/event",
       text: "<img src=\"http://example.com/picture\" width=\"20\" /> <a href=\"http://example.com/events/1234\">Event 1234</a>: <br /> urgent event"
    }
  ]
});
bradleyhilton
  • 376
  • 1
  • 3
  • 7
Aaron Ogle
  • 558
  • 3
  • 14
1

I had a similar need. What worked for me was using the image_url field, documented in the realtime API documentation:

module.exports = function(robot) {
  robot.respond(/image/i, function(res) {
        resposta = robot.adapter.customMessage({
            channel: room,
            attachments: [
                {
                   title: "Image",
                   title_link: "http://www.example.com",
                   image_url: "http://www.example.com/image.png",
                   text: "This image"
                }
            ]
        });
  });
};
OCarneiro
  • 327
  • 3
  • 6