Compare View

switch
from
...
to
 
Commits (3)

Changes

Showing 8 changed files Side-by-side Diff

lib/command-handler/buy.js
... ... @@ -6,6 +6,7 @@ const logger = require('komodo-sdk/logger');
6 6  
7 7 const commands = require('../command-group');
8 8 const commandError = require('./error');
  9 +const destinationCorrector = require('../destination-corrector');
9 10 const coreapi = require('../coreapi');
10 11  
11 12 const coreEndpoint = '/prepaid/buy';
... ... @@ -33,15 +34,17 @@ function execute(tokens, params, cb) {
33 34 logger.verbose('Rearrange tokens', {tokens: tokens});
34 35 }
35 36  
  37 + const destination = destinationCorrector((tokens[2] || '').trim());
  38 +
36 39 const coreParams = {
37 40 origin: params.origin,
38 41 report_ip: params.report_ip,
39 42 report_port: params.report_port,
40 43 terminal_name: params.from,
41 44 product_name: (tokens[1] || '').trim().toUpperCase(),
42   - destination: (tokens[2] || '').trim().replace(/^\+62/, '0'),
  45 + destination,
43 46 password: tokens[3],
44   - request_id: `${generateRequestId(tokens[1], tokens[2])}${Number(tokens[4]) ? '_req' + Number(tokens[4]) : ''}`,
  47 + request_id: `${generateRequestId(tokens[1], destination)}${Number(tokens[4]) ? '_req' + Number(tokens[4]) : ''}`,
45 48 postpaid: 0
46 49 };
47 50  
lib/command-handler/complain.js
... ... @@ -0,0 +1,33 @@
  1 +const CORE_ENDPOINT = '/complains/create';
  2 +
  3 +const commandError = require('./error');
  4 +const coreapi = require('../coreapi');
  5 +
  6 +function help(keyword) {
  7 + return `Untuk membuat keluhan, ketik perintah dengan format: ${ keyword.toUpperCase() }.<KELUHAN-ANDA>.<PIN>`;
  8 +}
  9 +
  10 +function execute(tokens, params, cb) {
  11 +
  12 + if (!tokens || tokens.length < 3) {
  13 + const responseParams = {
  14 + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`
  15 + }
  16 +
  17 + cb(null, null, responseParams);
  18 + return;
  19 + }
  20 +
  21 + const coreParams = {
  22 + asker_terminal_name: params.from,
  23 + asker_terminal_password: tokens[2],
  24 + message: tokens[1],
  25 + origin: params.origin,
  26 + report_ip: params.report_ip,
  27 + report_port: params.report_port,
  28 + };
  29 +
  30 + coreapi(CORE_ENDPOINT, coreParams, 'GET', cb);
  31 +}
  32 +
  33 +module.exports = execute;
0 34 \ No newline at end of file
lib/command-handler/index.js
... ... @@ -13,6 +13,7 @@ const handlerBalance = require(&#39;./balance&#39;);
13 13 const handlerBuy = require('./buy');
14 14 const handlerChangePin = require('./changepin');
15 15 const handlerClaimBonus = require('./claimbonus');
  16 +const handlerComplain = require('./complain');
16 17 const handlerDaySummary = require('./daysummary');
17 18 const handlerDepositTicket = require('./depositticket');
18 19 const handlerDisableDownline = require('./disabledownline');
... ... @@ -108,6 +109,9 @@ function execute(msg, params, cb) {
108 109 else if (commandGroup === 'pay') {
109 110 handlerPay(tokens, params, cb);
110 111 }
  112 + else if (commandGroup === 'complain') {
  113 + handlerComplain(tokens, params, cb);
  114 + }
111 115 else if (commandGroup === 'help') {
112 116 handlerHelp(tokens, params, cb)
113 117 }
lib/default-command.js
... ... @@ -232,6 +232,12 @@ module.exports = {
232 232 'tarikbonus',
233 233 'tarikrebate',
234 234 ],
  235 + complain: [
  236 + 'c',
  237 + 'complain',
  238 + 'komplain',
  239 + 'komplen',
  240 + ],
235 241 inquiry: [
236 242 'cektagihan',
237 243 'infotagihan',
lib/destination-corrector/index.js
... ... @@ -0,0 +1,25 @@
  1 +const util = require('./util');
  2 +
  3 +module.exports = (val, opts) => {
  4 + let result = val;
  5 + if (typeof result === 'number') {
  6 + result = result.toString();
  7 + }
  8 +
  9 + if (typeof result !== 'string') return val;
  10 +
  11 + result = result.trim();
  12 +
  13 + if (util.shouldNotProcessed(result)) return result;
  14 +
  15 + result = result
  16 + .replace(/\s+/g, '')
  17 + .replace(/-+/g, '')
  18 + .replace(/[();]/g, '');
  19 +
  20 + if (!opts || !opts.do_not_change_intl_code) {
  21 + result = result.replace(/^\+62/, '0');
  22 + }
  23 +
  24 + return result;
  25 +};
lib/destination-corrector/util.js
... ... @@ -0,0 +1 @@
  1 +exports.shouldNotProcessed = (val) => val.search(/[^0-9\s-()+;]/) >= 0;
1 1 {
2 2 "name": "komodo-center-messaging",
3   - "version": "0.11.0",
  3 + "version": "0.12.0",
4 4 "lockfileVersion": 1,
5 5 "requires": true,
6 6 "dependencies": {
1 1 {
2 2 "name": "komodo-center-messaging",
3   - "version": "0.11.0",
  3 + "version": "0.12.0",
4 4 "description": "Komodo Common Messaging Center",
5 5 "main": "index.js",
6 6 "scripts": {