Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / services / ami / trigger / cmContact / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xd9dd=['toLowerCase','merge','ioredis','util','../../../../config/environment','../../rpc/cmContact','defaults','redis','socket.io-emitter','[CM][%s][%s]','stringify','exec','data1','data2','isNil','data5','xmd-contactid','ListId','data3','split','$or','map','routeId','destcalleridnum','calleridnum','firstName','phone','mobile','updatedAt','resolve','then','isEmpty','length','info','[CM][%s][%s]\x20Contact\x20found:%s','uniqueid','[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]','join','[CM][%s][%s]\x20Contact\x20not\x20found','data4','calleridname','Unknown','destcalleridname','<unknown>','createContact','[CM][%s][%s]\x20Contact\x20created:%s','[CM][%s][%s]\x20Autocreate\x20disabled','format','user:%s','name','action'];(function(_0x13ff53,_0x5e1424){var _0x290228=function(_0x3e3133){while(--_0x3e3133){_0x13ff53['push'](_0x13ff53['shift']());}};_0x290228(++_0x5e1424);}(_0xd9dd,0x134));var _0xdd9d=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0xd9dd[_0x20a584];return _0x4b41a8;};'use strict';var _=require('lodash');var BPromise=require('bluebird');var Redis=require(_0xdd9d('0x0'));var util=require(_0xdd9d('0x1'));var config=require(_0xdd9d('0x2'));var logger=require('../../../../config/logger')('trigger');var cmContactRpc=require(_0xdd9d('0x3'));config['redis']=_[_0xdd9d('0x4')](config[_0xdd9d('0x5')],{'host':'localhost','port':0x18eb});var io=require(_0xdd9d('0x6'))(new Redis(config[_0xdd9d('0x5')]));function emit(_0x42c193,_0xf26224,_0x4a15da,_0x4ec311,_0x3f8f10){logger['info'](_0xdd9d('0x7'),_0x42c193,_0xf26224['id'],_0x4a15da,_0x4ec311,JSON[_0xdd9d('0x8')](_0x3f8f10));io['to'](_0x4a15da)['emit'](_0x4ec311,_0x3f8f10);}exports[_0xdd9d('0x9')]=function(_0x27a1cb,_0x5a43ee,_0x4eca1e,_0x919f25){var _0x570120,_0x138015;var _0x5ced11={};var _0x557457;var _0x323050=Number(_0x4eca1e[_0xdd9d('0xa')]);var _0x255424=_0x4eca1e[_0xdd9d('0xb')]?Boolean(Number(_0x4eca1e[_0xdd9d('0xb')])):![];var _0x55b118;var _0x9bb802=![];if(!_[_0xdd9d('0xc')](_0x4eca1e['data5'])){if(_0x4eca1e[_0xdd9d('0xd')]=='1')_0x9bb802=!![];}if(!_0x9bb802){if(_0x919f25['xmd-contactid']){_0x5ced11['id']=_0x919f25[_0xdd9d('0xe')];}}if(!_0x5ced11['id']){_0x5ced11[_0xdd9d('0xf')]=_0x323050;_0x55b118=_0x4eca1e['data3']&&_0x4eca1e[_0xdd9d('0x10')]!=='0'?_0x4eca1e[_0xdd9d('0x10')][_0xdd9d('0x11')](','):['phone'];_0x5ced11[_0xdd9d('0x12')]=_[_0xdd9d('0x13')](_0x55b118,function(_0x2c81cf){var _0x27e743={};_0x27e743[_0x2c81cf]=_0x919f25[_0xdd9d('0x14')]?_0x919f25[_0xdd9d('0x15')]:_0x919f25[_0xdd9d('0x16')];return _0x27e743;});_0x557457=_0x919f25['routeId']?_0x919f25[_0xdd9d('0x15')]:_0x919f25[_0xdd9d('0x16')];}var _0x163782=['id',_0xdd9d('0x17'),'lastName',_0xdd9d('0x18'),_0xdd9d('0x19'),'fax','ListId','createdAt','scheduledAt',_0xdd9d('0x1a')];var _0x4082a8=_['union'](_0x163782,_0x55b118);BPromise[_0xdd9d('0x1b')]()['then'](cmContactRpc['getContacts']({'attributes':_0x4082a8,'where':_0x5ced11,'phone':_0x557457}))[_0xdd9d('0x1c')](function(_0x5ee8b2){_0x138015=_0x5ee8b2;if(!_[_0xdd9d('0x1d')](_0x138015)){if(_0x138015[_0xdd9d('0x1e')]===0x1){_0x570120=_0x138015[0x0];logger[_0xdd9d('0x1f')](_0xdd9d('0x20'),_0x919f25[_0xdd9d('0x21')],_0x5a43ee['id'],_0x570120['id']);}else{logger['info'](_0xdd9d('0x22'),_0x919f25[_0xdd9d('0x21')],_0x5a43ee['id'],_[_0xdd9d('0x13')](_0x138015,'id')[_0xdd9d('0x23')](','));}return;}else{logger[_0xdd9d('0x1f')](_0xdd9d('0x24'),_0x919f25[_0xdd9d('0x21')],_0x5a43ee['id']);var _0x45ddb6={'ListId':_0x323050};var _0x44193b=_0x4eca1e[_0xdd9d('0x25')]&&_0x4eca1e[_0xdd9d('0x25')]!=='0'?_0x4eca1e['data4']:_0xdd9d('0x18');if(_0x255424){logger['info']('[CM][%s][%s]\x20Autocreate\x20enabled',_0x919f25['uniqueid'],_0x5a43ee['id']);_0x45ddb6[_0x44193b]=_[_0xdd9d('0xc')](_0x919f25[_0xdd9d('0x14')])?_0x919f25[_0xdd9d('0x16')]:_0x919f25[_0xdd9d('0x15')];if(_[_0xdd9d('0xc')](_0x919f25[_0xdd9d('0x14')])){_0x45ddb6[_0xdd9d('0x17')]=_0x919f25['calleridname']&&_0x919f25[_0xdd9d('0x26')]!=='<unknown>'?_0x919f25[_0xdd9d('0x26')]:_0xdd9d('0x27');}else{_0x45ddb6['firstName']=_0x919f25[_0xdd9d('0x28')]&&_0x919f25[_0xdd9d('0x28')]!==_0xdd9d('0x29')?_0x919f25['destcalleridname']:_0xdd9d('0x27');}return BPromise[_0xdd9d('0x1b')]()['then'](cmContactRpc[_0xdd9d('0x2a')](_0x45ddb6))[_0xdd9d('0x1c')](function(_0x132f8c){_0x570120=_0x132f8c;_0x138015['push'](_0x132f8c);if(_0x570120){logger['info'](_0xdd9d('0x2b'),_0x919f25[_0xdd9d('0x21')],_0x5a43ee['id'],_0x570120['id']);}return;});}else{logger[_0xdd9d('0x1f')](_0xdd9d('0x2c'),_0x919f25[_0xdd9d('0x21')],_0x5a43ee['id']);_0x45ddb6[_0x44193b]=_['isNil'](_0x919f25['routeId'])?_0x919f25[_0xdd9d('0x16')]:_0x919f25[_0xdd9d('0x15')];if(_[_0xdd9d('0xc')](_0x919f25['routeId'])){_0x45ddb6[_0xdd9d('0x17')]=_0x919f25['calleridname']&&_0x919f25[_0xdd9d('0x26')]!=='<unknown>'?_0x919f25[_0xdd9d('0x26')]:_0xdd9d('0x27');}else{_0x45ddb6[_0xdd9d('0x17')]=_0x919f25['destcalleridname']&&_0x919f25[_0xdd9d('0x28')]!=='<unknown>'?_0x919f25[_0xdd9d('0x28')]:_0xdd9d('0x27');}_0x570120=_0x45ddb6;_0x138015['push'](_0x45ddb6);return;}}})[_0xdd9d('0x1c')](function(){if(_0x27a1cb){emit(_0x919f25[_0xdd9d('0x21')],_0x5a43ee,util[_0xdd9d('0x2d')](_0xdd9d('0x2e'),_0x27a1cb[_0xdd9d('0x2f')]),util[_0xdd9d('0x2d')]('trigger:%s',_0x4eca1e[_0xdd9d('0x30')][_0xdd9d('0x31')]()),{'evt':_[_0xdd9d('0x32')](_0x919f25,{'autoCreate':_0x255424}),'contact':_0x570120===undefined?{}:_0x570120,'contacts':_0x138015[_0xdd9d('0x1e')]===0x0?undefined:_0x138015});}});};