From ded99cb653a803bd49e916d0b15de750e2a6c22d Mon Sep 17 00:00:00 2001 From: Gabriel Engel Date: Fri, 26 May 2017 15:16:28 -0300 Subject: [PATCH 01/10] dependencies upgrade --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c6d188560..e87326e2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hubot-rocketchat", - "version": "1.0.8", + "version": "1.0.9", "author": { "name": "Rocket.Chat", "url": "https://rocket.chat/" @@ -33,13 +33,13 @@ "email": "support@rocket.chat" }, "devDependencies": { - "coffee-script": "~1.7.1" + "coffee-script": "~1.12.6" }, "main": "./src/rocketchat", "dependencies": { "asteroid": "https://github.com/RocketChat/asteroid.git", "parent-require": "^1.0.0", - "q": "^1.4.1", - "lru-cache": "~4.0.0" + "q": "^1.5.0", + "lru-cache": "~4.0.2" } } From 9fdea9633d20659272de4dc25fe14351958cc800 Mon Sep 17 00:00:00 2001 From: Qi Yin Date: Fri, 7 Jul 2017 00:33:16 +0800 Subject: [PATCH 02/10] Hubot script to accept the room name (#214) * get room name * Increase the roomID, subsequent script send a custom message * revised comments indentation * fixed getRoomName spelling mistakes * fixed error of the indentation --- src/rocketchat.coffee | 14 ++++++++++---- src/rocketchat_driver.coffee | 12 ++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/rocketchat.coffee b/src/rocketchat.coffee index 1e6991b5a..7cbfd3ceb 100644 --- a/src/rocketchat.coffee +++ b/src/rocketchat.coffee @@ -155,11 +155,13 @@ class RocketChatBotAdapter extends Adapter @lastts = curts user = @robot.brain.userForId newmsg.u._id, name: newmsg.u.username, alias: newmsg.alias - user.room = newmsg.rid - if newmsg.t is 'uj' - @robot.receive new EnterMessage user, null, newmsg._id - else + @chatdriver.getRoomName(newmsg.rid).then((roomName)=> + user.room = roomName + user.roomID = newmsg.rid + if newmsg.t is 'uj' + @robot.receive new EnterMessage user, null, newmsg._id + else # check for the presence of attachments in the message if newmsg.file? and newmsg.attachments.length attachment = newmsg.attachments[0] @@ -184,6 +186,10 @@ class RocketChatBotAdapter extends Adapter message.text = "#{ @robot.name } #{ message.text }" @robot.receive message @robot.logger.info "Message sent to hubot brain." + ).catch((roomErr) => + @robot.logger.error "Unable to get room name: #{JSON.stringify(roomErr)} Reason: #{roomErr.reason}" + throw roomErr + ) ) .then(() => @emit 'connected' diff --git a/src/rocketchat_driver.coffee b/src/rocketchat_driver.coffee index e0e42a477..60abfd98d 100644 --- a/src/rocketchat_driver.coffee +++ b/src/rocketchat_driver.coffee @@ -8,22 +8,23 @@ LRU = require('lru-cache') # TODO: need to grab these values from process.env[] _msgsubtopic = 'stream-room-messages' # 'messages' -_msgsublimit = 10 # this is not actually used right now +_msgsublimit = 10 # this is not actually used right now _messageCollection = 'stream-room-messages' # room id cache _roomCacheSize = parseInt(process.env.ROOM_ID_CACHE_SIZE) || 10 _directMessageRoomCacheSize = parseInt(process.env.DM_ROOM_ID_CACHE_SIZE) || 100 _cacheMaxAge = parseInt(process.env.ROOM_ID_CACHE_MAX_AGE) || 300 -_roomIdCache = LRU( max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge ) -_directMessageRoomIdCache = LRU( max: _directMessageRoomCacheSize, maxAge: 1000 * _cacheMaxAge ) +_roomIdCache = LRU(max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge) +_directMessageRoomIdCache = LRU(max: _directMessageRoomCacheSize, maxAge: 1000 * _cacheMaxAge) +_roomNameCache = LRU(max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge) # driver specific to Rocketchat hubot integration # plugs into generic rocketchatbotadapter class RocketChatDriver constructor: (url, ssl, @logger, cb) -> - if ssl is 'true' + if ssl is 'true' sslenable = true else sslenable = false @@ -39,6 +40,9 @@ class RocketChatDriver getRoomId: (room) => @tryCache _roomIdCache, 'getRoomIdByNameOrId', room, 'Room ID' + getRoomName: (room) => + @tryCache _roomNameCache, 'getRoomNameById', room, 'Room Name' + getDirectMessageRoomId: (username) => @tryCache _directMessageRoomIdCache, 'createDirectMessage', username, 'DM Room ID' From 8209708ee9755eafcfb5e1f01e357be90ca0166a Mon Sep 17 00:00:00 2001 From: rhew Date: Thu, 6 Jul 2017 12:35:46 -0400 Subject: [PATCH 03/10] Fix typos (#207) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a1ab8cd8..ed60090be 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Feel free to join us in the [#hubot](https://demo.rocket.chat/channel/hubot) cha The latest version of the adapter is only compatible with 0.37.1 and higher of Rocket.Chat Server. -If you are using Rocket.Chat 0.35.0 or earilier, please use v0.1.4 of the adapter. (releases between 0.35.0 and 0.37.1 are not recommended for hubot operations) +If you are using Rocket.Chat 0.35.0 or earlier, please use v0.1.4 of the adapter. (releases between 0.35.0 and 0.37.1 are not recommended for hubot operations) #### NOTE If you want to integrate Rocket.Chat with GitHub or GitLab. Make sure you visit the [Rocket.Chat.Ops](https://github.com/RocketChat/Rocket.Chat.Ops) project before starting. We already have many scripts that add webhook events and access GitHub/GitLab APIs. You can easily extend these scripts for your custom application. @@ -162,7 +162,7 @@ Environment Variable | Description ROCKETCHAT_URL | the URL where Rocket.Chat is running, can be specified as `host:port` or `http://host:port` or `https://host:port`. If you are using `https://`, you **MUST** setup websocket pass-through on your reverse proxy (NGINX, and so on) with a valid certificate (not self-signed). Directly accessing Rocket.Chat without a reverse proxy via `https://` is not possible. ROCKETCHAT_USER | the bot user's name. It must be a registered user on your Rocket.Chat server, and the user must be granted `bot` role via Rocket.Chat's administrator's panel (note that this will also be the name that you can summon the bot with) ROCKETCHAT_PASSWORD | the bot user's password -ROCKETCHAT_AUTH | defaults to 'password' if undefinied, or set to 'ldap' if your use LDAP accounts for bots. +ROCKETCHAT_AUTH | defaults to 'password' if undefined, or set to 'ldap' if your use LDAP accounts for bots. ROCKETCHAT_ROOM | the channel/channels names the bot should listen to message from. This can be comma separated list. LISTEN_ON_ALL_PUBLIC | if 'true' then bot will listen and respond to messages from all public channels, as well as respond to direct messages. Default to 'false'. ROCKETCHAT_ROOM should be set to empty (with `ROCKETCHAT_ROOM=''` ) when using `LISTEN_ON_ALL_PUBLIC`. *IMPORTANT NOTE*: This option also allows the bot to listen and respond to messages _from all newly created private groups_ that the bot's user has been added as a member. RESPOND_TO_DM | if 'true' then bot will listen and respond to direct messages. When setting the option to 'true', be sure to also set ROCKETCHAT_ROOM. This option needs not be set if you are including LISTEN_ON_ALL_PUBLIC. Default is 'false'. @@ -194,7 +194,7 @@ And: ``` rocketbot help ``` -The example bot under `scripts` directory respeonds to: +The example bot under `scripts` directory responds to: ``` rocketbot report status ``` @@ -295,6 +295,6 @@ Once received, the bot: Q: The architecture of hubot-rocketchat looks interesting, can you tell me more about it? -A: Sure, it is based on hubot-meteorchat. hubot-meteorchat is the hubot integration project for Meteor based chats and real-time messaging systems. Its driver based architecture simplifies creation and cusotmization of adapter for new systems. For example, the hubot-rocketchat integration is just hubot-meteorchat + Rocket.Chat driver. +A: Sure, it is based on hubot-meteorchat. hubot-meteorchat is the hubot integration project for Meteor based chats and real-time messaging systems. Its driver based architecture simplifies creation and customization of adapter for new systems. For example, the hubot-rocketchat integration is just hubot-meteorchat + Rocket.Chat driver. Learn more about hubot-meteorchat and other available drivers [at this link](https://github.com/Sing-Li/hubot-meteorchat). From 28fa93a7689de4276797db528da3ae0a5ce516d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20Xia=28=E5=A4=8F=E6=81=BA=29?= Date: Fri, 7 Jul 2017 02:37:34 +1000 Subject: [PATCH 04/10] fix attachment test logic. close #193 (#194) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix attachment test logic. close #193 Also, retain the message text while init a new attachment. Signed-off-by: Xia Kai(夏恺) * fix this test for normal text-only message. Signed-off-by: Xia Kai(夏恺) --- src/rocketchat.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rocketchat.coffee b/src/rocketchat.coffee index 7cbfd3ceb..1ddf63736 100644 --- a/src/rocketchat.coffee +++ b/src/rocketchat.coffee @@ -163,7 +163,7 @@ class RocketChatBotAdapter extends Adapter @robot.receive new EnterMessage user, null, newmsg._id else # check for the presence of attachments in the message - if newmsg.file? and newmsg.attachments.length + if newmsg.attachments? and newmsg.attachments.length attachment = newmsg.attachments[0] if attachment.image_url? @@ -176,7 +176,7 @@ class RocketChatBotAdapter extends Adapter attachment.link = "#{RocketChatURL}#{attachment.video_url}" attachment.type = 'video' - message = new AttachmentMessage user, attachment, attachment.title, newmsg._id + message = new AttachmentMessage user, attachment, newmsg.msg, newmsg._id else message = new TextMessage user, newmsg.msg, newmsg._id From 17b6475c28937614692ff71ce8523a4802809b95 Mon Sep 17 00:00:00 2001 From: Tim Kinnane Date: Fri, 7 Jul 2017 02:47:26 +1000 Subject: [PATCH 05/10] Wrap sendMessage in Q promise. (#197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I found that `asteroid.call('sendMessage', message)` did not always return a promise, or possibly a "partially functional" then. This was breaking my promise chains in Hubot methods that invoked `sendMessageByRoomId`. So I wrapped it in `Q` as described in Q docs... >When working with promises provided by other libraries, you should convert it to a Q promise. Not all promise libraries make the same guarantees as Q and certainly don’t provide all of the same methods. Most libraries only provide a partially functional then method. This thankfully is all we need to turn them into vibrant Q promises. --- src/rocketchat_driver.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rocketchat_driver.coffee b/src/rocketchat_driver.coffee index 60abfd98d..86658fa91 100644 --- a/src/rocketchat_driver.coffee +++ b/src/rocketchat_driver.coffee @@ -83,7 +83,7 @@ class RocketChatDriver sendMessageByRoomId: (content, roomid) => message = @prepareMessage content, roomid - @asteroid.call('sendMessage', message) + Q(@asteroid.call('sendMessage', message)) .then (result)-> @logger.debug('[sendMessage] Success:', result) .catch (error) -> From 00ac343a042c1024e3e50e8b7bfa34570c02ec2c Mon Sep 17 00:00:00 2001 From: Vikas Kedia Date: Thu, 6 Jul 2017 23:04:04 +0530 Subject: [PATCH 06/10] Updating the node version to 6.10.3 (#216) * Updating the node version to 6.10.3 Since 1. as per node version 6 release notes it is 4 times faster than node 4. 2. 0.12 version is deprecated. * Use same version as rocket.chat --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d0bbe9967..a896796c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:0.12.4 +FROM node:4.8.3 MAINTAINER Rocket.Chat Team RUN npm install -g coffee-script yo generator-hubot && \ From 9f9e0db1ffba557ee01fcd5c8e83380a22088b81 Mon Sep 17 00:00:00 2001 From: Gustavo Aguiar Date: Thu, 6 Jul 2017 14:35:37 -0300 Subject: [PATCH 07/10] feat: handle livechat message (#211) * feat: handle livechat message * fix: answer first message on Livechat --- src/rocketchat.coffee | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rocketchat.coffee b/src/rocketchat.coffee index 1ddf63736..d156b3061 100644 --- a/src/rocketchat.coffee +++ b/src/rocketchat.coffee @@ -21,6 +21,7 @@ RocketChatUser = process.env.ROCKETCHAT_USER or "hubot" RocketChatPassword = process.env.ROCKETCHAT_PASSWORD or "password" ListenOnAllPublicRooms = (process.env.LISTEN_ON_ALL_PUBLIC or "false").toLowerCase() is 'true' RespondToDirectMessage = (process.env.RESPOND_TO_DM or "false").toLowerCase() is 'true' +RespondToLivechatMessage = (process.env.RESPOND_TO_LIVECHAT or "false").toLowerCase() is "true" RespondToEditedMessage = (process.env.RESPOND_TO_EDITED or "false").toLowerCase() is 'true' SSLEnabled = "false" @@ -141,7 +142,12 @@ class RocketChatBotAdapter extends Adapter if isDM and not RespondToDirectMessage return - if not isDM and not messageOptions.roomParticipant and not ListenOnAllPublicRooms + isLC = messageOptions.roomType is 'l' + + if isLC and not RespondToLivechatMessage + return + + if not isDM and not messageOptions.roomParticipant and not ListenOnAllPublicRooms and not RespondToLivechatMessage return curts = new Date(newmsg.ts.$date) @@ -182,7 +188,7 @@ class RocketChatBotAdapter extends Adapter startOfText = if message.text.indexOf('@') == 0 then 1 else 0 robotIsNamed = message.text.indexOf(@robot.name) == startOfText || message.text.indexOf(@robot.alias) == startOfText - if isDM and not robotIsNamed + if (isDM or isLC) and not robotIsNamed message.text = "#{ @robot.name } #{ message.text }" @robot.receive message @robot.logger.info "Message sent to hubot brain." From 242408881fbad144a409e6a8c9cff46ddc21b883 Mon Sep 17 00:00:00 2001 From: Jan Marker Date: Mon, 10 Jul 2017 11:12:51 -0500 Subject: [PATCH 08/10] Update Node version on Travis (#221) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6e7834887..54c394525 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ services: - docker language: node_js node_js: -- '0.10' +- '4.8.3' before_install: - npm install -g npm@'>=2.13.5' deploy: From ff7738158638447fdba3af8b4e8560593738e3c9 Mon Sep 17 00:00:00 2001 From: Kenichi Saita Date: Tue, 11 Jul 2017 01:14:00 +0900 Subject: [PATCH 09/10] Add missing emoji param to customMessage method (#220) --- src/rocketchat_driver.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rocketchat_driver.coffee b/src/rocketchat_driver.coffee index 86658fa91..177bb0558 100644 --- a/src/rocketchat_driver.coffee +++ b/src/rocketchat_driver.coffee @@ -99,7 +99,8 @@ class RocketChatDriver bot: true, groupable: false, alias: message.alias, - avatar: message.avatar + avatar: message.avatar, + emoji: message.emoji, }) login: (username, password) => From 4a71585b10f6e2861d46c3594e4c3ed55e804dbf Mon Sep 17 00:00:00 2001 From: Steffen Neubauer Date: Thu, 13 Jul 2017 19:37:15 +0200 Subject: [PATCH 10/10] Terrible hack to fix #203 (#204) --- src/rocketchat.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rocketchat.coffee b/src/rocketchat.coffee index d156b3061..40dacc9f4 100644 --- a/src/rocketchat.coffee +++ b/src/rocketchat.coffee @@ -85,6 +85,7 @@ class RocketChatBotAdapter extends Adapter @robot.logger.error "If joining GENERAL please make sure its using all caps." @robot.logger.error "If using LDAP, turn off LDAP, and turn on general user registration with email verification off." + process.exit 1 #hack to make hubot die on login error to fix #203 throw loginErr #rethrow to exit the chain ) # Get room IDS