2

我想从hubot准备格式化消息到rocketchat,但我找不到任何参考。

这是我的主要参考: http ://theprogrammingbutler.com/blog/archives/2011/10/28/hubot-scripts-explained/

我试过这个:

    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)

但我想更丰富和详细一些。

有什么建议吗??

谢谢。

4

2 回答 2

4

Rocket.Chat 的 hubot 适配器有一个名为 customMessage 的方法。您可以像使用 slack 一样包含附件,以实现丰富的消息。

要使用 customMessage,请使用以下内容:

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"
    }
  ]
});
于 2017-08-03T20:00:49.810 回答
1

我也有类似的需求。对我有用的是使用实时 API 文档image_url中记录的字段:

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"
                }
            ]
        });
  });
};
于 2018-02-01T19:25:00.517 回答