diff --git a/lib/config/index.js b/lib/config/index.js index 6107262..2775b26 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -9,13 +9,16 @@ * @license AGPL-3.0+ */ -module.exports = function Configuration (logger) { +module.exports = function Configuration (logger, configPath = null) { let config + if (configPath === null) { + configPath = './lib/config/config.json' + } try { - let data = require('fs').readFileSync('./lib/config/config.json') + let data = require('fs').readFileSync(configPath) config = JSON.parse(data) } catch (error) { - logger.fatal(`Invalid configuration file: ${error.message}`) + logger.fatal(`Invalid configuration file: ${error.message}, current directory is: ${process.cwd()}`) process.exit(99) } return { diff --git a/lib/xmpp/index.js b/lib/xmpp/index.js index 154b0ce..89d1d7f 100644 --- a/lib/xmpp/index.js +++ b/lib/xmpp/index.js @@ -12,6 +12,7 @@ module.exports = (logger, config) => { const xmpp = require('simple-xmpp') + const outgoing = require('../outgoing') this.jid = null // handle connection @@ -30,15 +31,15 @@ module.exports = (logger, config) => { xmpp.on('chat', function (from, message) { logger.info(`Incoming chat message from ${from}`) logger.debug(`Message: "${message}"`) - let xmppHook = config.getXmppHookAction('bot') + let xmppHook = config.getXmppHookAction(this.jid) if (!xmppHook) { - logger.error('There is no action for incoming chat message from bot') + logger.error(`There is no action for incoming chat message to ${this.jid}`) return } switch (xmppHook.action) { case 'outgoing_webhook': logger.debug(`Call outgoing webhook: ${xmppHook.args[0]}`) - require('../outgoing')(logger, config, xmpp, from, from, message, false, xmppHook.args[0]) + outgoing(logger, config, xmpp, from, from, message, false, xmppHook.args[0]) break default: break @@ -62,7 +63,7 @@ module.exports = (logger, config) => { switch (xmppHook.action) { case 'outgoing_webhook': logger.debug(`Call outgoing webhook: ${xmppHook.args[0]}`) - require('../outgoing')(logger, config, xmpp, from, conference, message, true, xmppHook.args[0]) + outgoing(logger, config, xmpp, from, conference, message, true, xmppHook.args[0]) break default: break