diff --git a/package.json b/package.json index 4d67ba1..547edb6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hubot-matrix", - "version": "1.0.0", + "version": "1.1.0", "description": "Matrix adapter for hubot", "main": "src/matrix.coffee", "scripts": { diff --git a/src/matrix.coffee b/src/matrix.coffee index 3b0b380..1a3f96e 100644 --- a/src/matrix.coffee +++ b/src/matrix.coffee @@ -5,6 +5,7 @@ catch {Robot,Adapter,TextMessage,User} = prequire 'hubot' sdk = require 'matrix-js-sdk' +request = require 'request' class Matrix extends Adapter constructor: -> @@ -14,12 +15,23 @@ class Matrix extends Adapter send: (envelope, strings...) -> for str in strings @robot.logger.info "Sending to #{envelope.room}: #{str}" - @client.sendTextMessage envelope.room, str + if /^(f|ht)tps?:\/\//i.test(str) + @sendImage envelope, str + else + @client.sendTextMessage envelope.room, str reply: (envelope, strings...) -> for str in strings @send envelope, "#{envelope.user.name}: #{str}" + sendImage: (envelope, url) -> + @client.uploadContent(stream: request url, name: url).done (murl) => + @client.sendMessage envelope.room, { + msgtype: "m.image", + body: url, + url: JSON.parse(murl).content_uri + } + run: -> @robot.logger.info "Run #{@robot.name}" client = sdk.createClient('https://matrix.org')