Skip to content

Commit

Permalink
fix(listener): Load order issue resolved
Browse files Browse the repository at this point in the history
fixes #269
+ simplified adapter usage
+ call adapter super receive method instead of replace
+ update to org scope deps
  • Loading branch information
timkinnane committed Apr 3, 2018
1 parent 05a036d commit b170bab
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 51 deletions.
25 changes: 12 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const Adapter = require('hubot/src/adapter')
const Response = require('hubot/src/response')
const { TextMessage, EnterMessage, LeaveMessage } = require('hubot/src/message')
const pkg = require('./package.json')
const { driver } = require('rocketchat-sdk')
'use strict'

const Adapter = require.main.require('hubot/src/adapter')
const Response = require.main.require('hubot/src/response')
const { TextMessage, EnterMessage, LeaveMessage } = require.main.require('hubot/src/message')
const { driver } = require('@rocket.chat/sdk')

/** Take configs from environment settings or defaults */
const config = {
Expand Down Expand Up @@ -44,6 +45,8 @@ class AttachmentMessage extends TextMessage {
/** Main API for Hubot on Rocket.Chat */
class RocketChatBotAdapter extends Adapter {
run () {
this.robot.logger.info(`[startup] Rocket.Chat adapter in use`)

// Print logs with current configs
this.startupLogs()

Expand Down Expand Up @@ -87,14 +90,14 @@ class RocketChatBotAdapter extends Adapter {
throw err
})
.then(() => {
driver.reactToMessages(this.receive.bind(this)) // reactive callback
driver.reactToMessages(this.process.bind(this)) // reactive callback
this.emit('connected') // tells hubot to load scripts
})
}

/** Process every incoming message in subscription */
// @todo: break into process components for unit testing
receive (err, message, msgOpts) {
process (err, message, msgOpts) {
if (err) {
this.robot.logger.error(`Unable to receive messages ${JSON.stringify(err)}`)
throw err
Expand Down Expand Up @@ -255,9 +258,5 @@ class RocketChatBotAdapter extends Adapter {
}
}

module.exports = {
use: (robot) => {
robot.logger.info(`[startup] Rocket.Chat adapter version ${pkg.version} in use`)
return new RocketChatBotAdapter(robot)
}
}
exports.use = (robot) => new RocketChatBotAdapter(robot)

74 changes: 38 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
},
"main": "index.js",
"dependencies": {
"hubot": "https://github.com/hubotio/hubot.git#v3.0.1",
"rocketchat-sdk": "^0.0.1"
"hubot": "3",
"@rocket.chat/sdk": "^0.0.2"
},
"peerDependencies": {
"hubot": "3"
}
}

0 comments on commit b170bab

Please sign in to comment.