image upload

This commit is contained in:
David A Roberts 2015-12-05 14:02:04 +10:00
parent 86fdbaf45c
commit 7b83cbc5d7
2 changed files with 14 additions and 2 deletions

View File

@ -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": {

View File

@ -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')