hubot-bearychat
Advanced tools
+7
-0
| ---- | ||
| - Name: hubot-bearychat | ||
| ---- | ||
| # 0.7.0 / 2017-06-07 | ||
| ## Added | ||
| - 支持 `robot.messageRoom` 方法 | ||
| # 0.6.0 / 2017-05-16 | ||
@@ -5,0 +12,0 @@ |
+1
-1
| { | ||
| "name": "hubot-bearychat", | ||
| "version": "0.6.0", | ||
| "version": "0.7.0", | ||
| "description": "BearyChat adapter for hubot", | ||
@@ -5,0 +5,0 @@ "main": "./src/bearychat", |
+13
-4
@@ -101,8 +101,8 @@ # hubot-bearychat | ||
| ### at 回复 `Reply` | ||
| ### 回复 `Reply` | ||
| 如果 hubot 在回复消息的同时想要提及消息作者,可以使用 `res.reply`: | ||
| 如果 hubot 在回复消息的同时想要引用作者的消息,可以使用 `res.reply`: | ||
| ``` | ||
| robot.hear 'how old are you?', (res) -> | ||
| robot.hear /how old are you?/, (res) -> | ||
| res.reply 'I am Five!' | ||
@@ -113,2 +113,11 @@ ``` | ||
| ### 向其他讨论组发消息 | ||
| 如果想让 Hubot 往非当前对话的讨论组发送消息可以使用 `robot.messageRoom`, 参数是 vchannelId,讨论组名称也即将支持。 | ||
| ``` | ||
| robot.hear /voldemort/i, (res) -> | ||
| robot.messageRoom(vchannel_id, "Somebody is talking about you, Voldemort!") | ||
| ``` | ||
| ### 富文本回复 `bearychat.attachment` | ||
@@ -119,3 +128,3 @@ | ||
| ``` | ||
| robot.respond '念两句诗', (res) -> | ||
| robot.respond /念两句诗/, (res) -> | ||
| robot.emit 'bearychat.attachment', | ||
@@ -122,0 +131,0 @@ # required |
+12
-3
@@ -109,6 +109,6 @@ # hubot-bearychat | ||
| If hubot want to response a message and mention the caller, use `res.reply`: | ||
| If hubot want to response a message and refer the caller`s message, use `res.reply`: | ||
| ``` | ||
| robot.hear 'how old are you?', (res) -> | ||
| robot.hear /how old are you?/, (res) -> | ||
| res.reply 'I am Five!' | ||
@@ -119,2 +119,11 @@ ``` | ||
| ### Send message to other room | ||
| If you want to send a message to other channel use `robot.messageRoom` with vchannel_id, and Channel Name support is coming soon: | ||
| ``` | ||
| robot.hear /voldemort/i, (res) -> | ||
| robot.messageRoom(vchannel_id, "Somebody is talking about you, Voldemort!") | ||
| ``` | ||
| ### `bearychat.attachment` | ||
@@ -125,3 +134,3 @@ | ||
| ``` | ||
| robot.respond '念两句诗', (res) -> | ||
| robot.respond /念两句诗/, (res) -> | ||
| robot.emit 'bearychat.attachment', | ||
@@ -128,0 +137,0 @@ # required |
@@ -45,4 +45,8 @@ {Adapter} = require 'hubot' | ||
| send: (envelope, strings...) -> | ||
| message = @client.packMessage false, envelope, strings | ||
| @client.sendMessage envelope, message | ||
| if envelope.room # robot.messageRoom | ||
| message = {text: strings[0]} | ||
| @client.sendMessageToRoom envelope, message | ||
| else | ||
| message = @client.packMessage false, envelope, strings | ||
| @client.sendMessage envelope, message | ||
@@ -49,0 +53,0 @@ reply: (envelope, strings...) -> |
+20
-11
| EventEmitter = require 'events' | ||
| bearychat = require 'bearychat' | ||
| { | ||
@@ -20,18 +22,25 @@ User, | ||
| sendMessage: (envelope, message) -> | ||
| {_,token} = envelope.user | ||
| url = "https://bearychat.com/api/rtm/message" | ||
| message = Object.assign {token:token},message | ||
| message = JSON.stringify message | ||
| {token} = envelope.user | ||
| message = Object.assign {token: token, attachments: []}, message | ||
| bearychat.message.create(message).catch (err) => | ||
| @emit(EventError, err) | ||
| @robot.logger.error 'send message failed', err | ||
| @robot.http(url) | ||
| .header('Content-Type', 'application/json') | ||
| .post(message) (err, res, body) => | ||
| @robot.logger.debug(body) | ||
| @emit(EventError, err) if err | ||
| sendMessageToRoom: (envelope, message) -> | ||
| vchannelId = envelope.room | ||
| bearychat.message.create({ | ||
| token: @tokens[0], | ||
| vchannel_id: vchannelId, | ||
| text: message.text, | ||
| attachments: message.attachments or [] | ||
| }) | ||
| packMessage: (isReply, envelope, [text, opts]) -> | ||
| text = "@#{envelope.user.name}: #{text}" if isReply | ||
| Object.assign opts || {},{sender: envelope.user.sender,vchannel: envelope.user.vchannel,text: text} | ||
| Object.assign opts || {}, { | ||
| sender: envelope.user.sender, | ||
| vchannel_id: envelope.user.vchannel, | ||
| text: text | ||
| } | ||
| receiveMessageCallback: (req, res) -> | ||
@@ -38,0 +47,0 @@ body = req.body |
| EventEmitter = require 'events' | ||
| WebSocket = require 'ws' | ||
| { User, TextMessage } = require 'hubot' | ||
| { rtm } = require 'bearychat' | ||
| bearychat = require 'bearychat' | ||
| rtm = bearychat.rtm | ||
@@ -94,2 +95,11 @@ { | ||
| sendMessageToRoom: (envelope, message) -> | ||
| vchannelId = envelope.room | ||
| bearychat.message.create({ | ||
| token: @token, | ||
| vchannel_id: vchannelId, | ||
| text: message.text, | ||
| attachments: [] | ||
| }) | ||
| connectToRTM: (wsHost) -> | ||
@@ -96,0 +106,0 @@ @rtmCallId = 0 |
| root = true | ||
| [*] | ||
| charset = utf8 | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
| [*.js] | ||
| indent_size = 2 |
126732
0.9%159
6%16
-5.88%