Skip to content

Commit 76b9c3f

Browse files
committed
2 parents f02f5f1 + 4a71585 commit 76b9c3f

File tree

6 files changed

+41
-23
lines changed

6 files changed

+41
-23
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
- docker
44
language: node_js
55
node_js:
6-
- '0.10'
6+
- '4.8.3'
77
before_install:
88
- npm install -g npm@'>=2.13.5'
99
deploy:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:0.12.4
1+
FROM node:4.8.3
22
MAINTAINER Rocket.Chat Team <buildmaster@rocket.chat>
33

44
RUN npm install -g coffee-script yo generator-hubot && \

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Feel free to join us in the [#hubot](https://demo.rocket.chat/channel/hubot) cha
1414

1515
The latest version of the adapter is only compatible with 0.37.1 and higher of Rocket.Chat Server.
1616

17-
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)
17+
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)
1818

1919
#### NOTE
2020
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
162162
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.
163163
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)
164164
ROCKETCHAT_PASSWORD | the bot user's password
165-
ROCKETCHAT_AUTH | defaults to 'password' if undefinied, or set to 'ldap' if your use LDAP accounts for bots.
165+
ROCKETCHAT_AUTH | defaults to 'password' if undefined, or set to 'ldap' if your use LDAP accounts for bots.
166166
ROCKETCHAT_ROOM | the channel/channels names the bot should listen to message from. This can be comma separated list.
167167
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.
168168
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:
194194
```
195195
rocketbot help
196196
```
197-
The example bot under `scripts` directory respeonds to:
197+
The example bot under `scripts` directory responds to:
198198
```
199199
rocketbot report status
200200
```
@@ -295,6 +295,6 @@ Once received, the bot:
295295

296296
Q: The architecture of hubot-rocketchat looks interesting, can you tell me more about it?
297297

298-
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.
298+
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.
299299

300300
Learn more about hubot-meteorchat and other available drivers [at this link](https://github.com/Sing-Li/hubot-meteorchat).

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
"email": "support@rocket.chat"
3434
},
3535
"devDependencies": {
36-
"coffee-script": "~1.7.1"
36+
"coffee-script": "~1.12.6"
3737
},
3838
"main": "./src/rocketchat",
3939
"dependencies": {
4040
"asteroid": "https://github.com/RocketChat/asteroid.git",
4141
"parent-require": "^1.0.0",
42-
"q": "^1.4.1",
43-
"lru-cache": "~4.0.0"
42+
"q": "^1.5.0",
43+
"lru-cache": "~4.0.2"
4444
}
4545
}

src/rocketchat.coffee

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ RocketChatUser = process.env.ROCKETCHAT_USER or "hubot"
2121
RocketChatPassword = process.env.ROCKETCHAT_PASSWORD or "password"
2222
ListenOnAllPublicRooms = (process.env.LISTEN_ON_ALL_PUBLIC or "false").toLowerCase() is 'true'
2323
RespondToDirectMessage = (process.env.RESPOND_TO_DM or "false").toLowerCase() is 'true'
24+
RespondToLivechatMessage = (process.env.RESPOND_TO_LIVECHAT or "false").toLowerCase() is "true"
2425
RespondToEditedMessage = (process.env.RESPOND_TO_EDITED or "false").toLowerCase() is 'true'
2526
SSLEnabled = "false"
2627

@@ -84,6 +85,7 @@ class RocketChatBotAdapter extends Adapter
8485
@robot.logger.error "If joining GENERAL please make sure its using all caps."
8586
@robot.logger.error "If using LDAP, turn off LDAP, and turn on general user registration with email
8687
verification off."
88+
process.exit 1 #hack to make hubot die on login error to fix #203
8789
throw loginErr #rethrow to exit the chain
8890
)
8991
# Get room IDS
@@ -141,7 +143,12 @@ class RocketChatBotAdapter extends Adapter
141143
if isDM and not RespondToDirectMessage
142144
return
143145

144-
if not isDM and not messageOptions.roomParticipant and not ListenOnAllPublicRooms
146+
isLC = messageOptions.roomType is 'l'
147+
148+
if isLC and not RespondToLivechatMessage
149+
return
150+
151+
if not isDM and not messageOptions.roomParticipant and not ListenOnAllPublicRooms and not RespondToLivechatMessage
145152
return
146153

147154
curts = new Date(newmsg.ts.$date)
@@ -155,13 +162,15 @@ class RocketChatBotAdapter extends Adapter
155162
@lastts = curts
156163

157164
user = @robot.brain.userForId newmsg.u._id, name: newmsg.u.username, alias: newmsg.alias
158-
user.room = newmsg.rid
159165

160-
if newmsg.t is 'uj'
161-
@robot.receive new EnterMessage user, null, newmsg._id
162-
else
166+
@chatdriver.getRoomName(newmsg.rid).then((roomName)=>
167+
user.room = roomName
168+
user.roomID = newmsg.rid
169+
if newmsg.t is 'uj'
170+
@robot.receive new EnterMessage user, null, newmsg._id
171+
else
163172
# check for the presence of attachments in the message
164-
if newmsg.file? and newmsg.attachments.length
173+
if newmsg.attachments? and newmsg.attachments.length
165174
attachment = newmsg.attachments[0]
166175

167176
if attachment.image_url?
@@ -174,16 +183,20 @@ class RocketChatBotAdapter extends Adapter
174183
attachment.link = "#{RocketChatURL}#{attachment.video_url}"
175184
attachment.type = 'video'
176185

177-
message = new AttachmentMessage user, attachment, attachment.title, newmsg._id
186+
message = new AttachmentMessage user, attachment, newmsg.msg, newmsg._id
178187
else
179188
message = new TextMessage user, newmsg.msg, newmsg._id
180189

181190
startOfText = if message.text.indexOf('@') == 0 then 1 else 0
182191
robotIsNamed = message.text.indexOf(@robot.name) == startOfText || message.text.indexOf(@robot.alias) == startOfText
183-
if isDM and not robotIsNamed
192+
if (isDM or isLC) and not robotIsNamed
184193
message.text = "#{ @robot.name } #{ message.text }"
185194
@robot.receive message
186195
@robot.logger.info "Message sent to hubot brain."
196+
).catch((roomErr) =>
197+
@robot.logger.error "Unable to get room name: #{JSON.stringify(roomErr)} Reason: #{roomErr.reason}"
198+
throw roomErr
199+
)
187200
)
188201
.then(() =>
189202
@emit 'connected'

src/rocketchat_driver.coffee

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ LRU = require('lru-cache')
88
# TODO: need to grab these values from process.env[]
99

1010
_msgsubtopic = 'stream-room-messages' # 'messages'
11-
_msgsublimit = 10 # this is not actually used right now
11+
_msgsublimit = 10 # this is not actually used right now
1212
_messageCollection = 'stream-room-messages'
1313

1414
# room id cache
1515
_roomCacheSize = parseInt(process.env.ROOM_ID_CACHE_SIZE) || 10
1616
_directMessageRoomCacheSize = parseInt(process.env.DM_ROOM_ID_CACHE_SIZE) || 100
1717
_cacheMaxAge = parseInt(process.env.ROOM_ID_CACHE_MAX_AGE) || 300
18-
_roomIdCache = LRU( max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge )
19-
_directMessageRoomIdCache = LRU( max: _directMessageRoomCacheSize, maxAge: 1000 * _cacheMaxAge )
18+
_roomIdCache = LRU(max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge)
19+
_directMessageRoomIdCache = LRU(max: _directMessageRoomCacheSize, maxAge: 1000 * _cacheMaxAge)
20+
_roomNameCache = LRU(max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge)
2021

2122
# driver specific to Rocketchat hubot integration
2223
# plugs into generic rocketchatbotadapter
2324

2425
class RocketChatDriver
2526
constructor: (url, ssl, @logger, cb) ->
26-
if ssl is 'true'
27+
if ssl is 'true'
2728
sslenable = true
2829
else
2930
sslenable = false
@@ -39,6 +40,9 @@ class RocketChatDriver
3940
getRoomId: (room) =>
4041
@tryCache _roomIdCache, 'getRoomIdByNameOrId', room, 'Room ID'
4142

43+
getRoomName: (room) =>
44+
@tryCache _roomNameCache, 'getRoomNameById', room, 'Room Name'
45+
4246
getDirectMessageRoomId: (username) =>
4347
@tryCache _directMessageRoomIdCache, 'createDirectMessage', username, 'DM Room ID'
4448

@@ -79,7 +83,7 @@ class RocketChatDriver
7983

8084
sendMessageByRoomId: (content, roomid) =>
8185
message = @prepareMessage content, roomid
82-
@asteroid.call('sendMessage', message)
86+
Q(@asteroid.call('sendMessage', message))
8387
.then (result)->
8488
@logger.debug('[sendMessage] Success:', result)
8589
.catch (error) ->
@@ -95,7 +99,8 @@ class RocketChatDriver
9599
bot: true,
96100
groupable: false,
97101
alias: message.alias,
98-
avatar: message.avatar
102+
avatar: message.avatar,
103+
emoji: message.emoji,
99104
})
100105

101106
login: (username, password) =>

0 commit comments

Comments
 (0)