diff --git a/lib/command-handler/complain.js b/lib/command-handler/complain.js new file mode 100644 index 0000000..3f4d5fd --- /dev/null +++ b/lib/command-handler/complain.js @@ -0,0 +1,33 @@ +const CORE_ENDPOINT = '/complains/create'; + +const commandError = require('./error'); +const coreapi = require('../coreapi'); + +function help(keyword) { + return `Untuk membuat keluhan, ketik perintah dengan format: ${ keyword.toUpperCase() }.<KELUHAN-ANDA>.<PIN>`; +} + +function execute(tokens, params, cb) { + + if (!tokens || tokens.length < 3) { + const responseParams = { + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` + } + + cb(null, null, responseParams); + return; + } + + const coreParams = { + asker_terminal_name: params.from, + asker_terminal_password: tokens[2], + message: tokens[1], + origin: params.origin, + report_ip: params.report_ip, + report_port: params.report_port, + }; + + coreapi(CORE_ENDPOINT, coreParams, 'GET', cb); +} + +module.exports = execute; \ No newline at end of file diff --git a/lib/command-handler/index.js b/lib/command-handler/index.js index 1a7ea7e..5f5a8ff 100644 --- a/lib/command-handler/index.js +++ b/lib/command-handler/index.js @@ -13,6 +13,7 @@ const handlerBalance = require('./balance'); const handlerBuy = require('./buy'); const handlerChangePin = require('./changepin'); const handlerClaimBonus = require('./claimbonus'); +const handlerComplain = require('./complain'); const handlerDaySummary = require('./daysummary'); const handlerDepositTicket = require('./depositticket'); const handlerDisableDownline = require('./disabledownline'); @@ -108,6 +109,9 @@ function execute(msg, params, cb) { else if (commandGroup === 'pay') { handlerPay(tokens, params, cb); } + else if (commandGroup === 'complain') { + handlerComplain(tokens, params, cb); + } else if (commandGroup === 'help') { handlerHelp(tokens, params, cb) } diff --git a/lib/default-command.js b/lib/default-command.js index 07be4b0..521ee2e 100644 --- a/lib/default-command.js +++ b/lib/default-command.js @@ -232,6 +232,12 @@ module.exports = { 'tarikbonus', 'tarikrebate', ], + complain: [ + 'c', + 'complain', + 'komplain', + 'komplen', + ], inquiry: [ 'cektagihan', 'infotagihan',