Built motion from commit d5e4af8c.|2.6.23
[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 _0x2067=['calleridname','<unknown>','destcalleridname','Unknown','resolve','[CM][%s][%s]\x20Contact\x20created:%s','push','format','trigger:%s','toLowerCase','lodash','ioredis','util','../../../../config/logger','../../rpc/cmContact','redis','defaults','localhost','[CM][%s][%s]','exec','data1','data2','isNil','data5','xmd-contactid','ListId','data3','split','phone','map','routeId','destcalleridnum','calleridnum','firstName','lastName','mobile','createdAt','updatedAt','union','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'];(function(_0x4ac60a,_0x503a99){var _0x4b22e8=function(_0x145c47){while(--_0x145c47){_0x4ac60a['push'](_0x4ac60a['shift']());}};_0x4b22e8(++_0x503a99);}(_0x2067,0x161));var _0x7206=function(_0x21cecb,_0x2872d2){_0x21cecb=_0x21cecb-0x0;var _0x191984=_0x2067[_0x21cecb];return _0x191984;};'use strict';var _=require(_0x7206('0x0'));var BPromise=require('bluebird');var Redis=require(_0x7206('0x1'));var util=require(_0x7206('0x2'));var config=require('../../../../config/environment');var logger=require(_0x7206('0x3'))('trigger');var cmContactRpc=require(_0x7206('0x4'));config[_0x7206('0x5')]=_[_0x7206('0x6')](config[_0x7206('0x5')],{'host':_0x7206('0x7'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function emit(_0x15c0c5,_0x3685f9,_0x559939,_0x2cf8da,_0x1ef65c){logger['info'](_0x7206('0x8'),_0x15c0c5,_0x3685f9['id'],_0x559939,_0x2cf8da,JSON['stringify'](_0x1ef65c));io['to'](_0x559939)['emit'](_0x2cf8da,_0x1ef65c);}exports[_0x7206('0x9')]=function(_0x164c54,_0x15eab9,_0x1b6e1f,_0xbca8b7){var _0x5c4362,_0x2e4a27;var _0x16e931={};var _0x2cfd59;var _0x277593=Number(_0x1b6e1f[_0x7206('0xa')]);var _0x2afd1a=_0x1b6e1f[_0x7206('0xb')]?Boolean(Number(_0x1b6e1f[_0x7206('0xb')])):![];var _0x55279e;var _0x2baee1=![];if(!_[_0x7206('0xc')](_0x1b6e1f['data5'])){if(_0x1b6e1f[_0x7206('0xd')]=='1')_0x2baee1=!![];}if(!_0x2baee1){if(_0xbca8b7[_0x7206('0xe')]){_0x16e931['id']=_0xbca8b7[_0x7206('0xe')];}}if(!_0x16e931['id']){_0x16e931[_0x7206('0xf')]=_0x277593;_0x55279e=_0x1b6e1f[_0x7206('0x10')]&&_0x1b6e1f[_0x7206('0x10')]!=='0'?_0x1b6e1f[_0x7206('0x10')][_0x7206('0x11')](','):[_0x7206('0x12')];_0x16e931['$or']=_[_0x7206('0x13')](_0x55279e,function(_0x2f53ea){var _0x19c547={};_0x19c547[_0x2f53ea]=_0xbca8b7[_0x7206('0x14')]?_0xbca8b7[_0x7206('0x15')]:_0xbca8b7[_0x7206('0x16')];return _0x19c547;});_0x2cfd59=_0xbca8b7[_0x7206('0x14')]?_0xbca8b7[_0x7206('0x15')]:_0xbca8b7[_0x7206('0x16')];}var _0x15432b=['id',_0x7206('0x17'),_0x7206('0x18'),'phone',_0x7206('0x19'),'fax',_0x7206('0xf'),_0x7206('0x1a'),'scheduledAt',_0x7206('0x1b')];var _0x292d53=_[_0x7206('0x1c')](_0x15432b,_0x55279e);BPromise['resolve']()[_0x7206('0x1d')](cmContactRpc['getContacts']({'attributes':_0x292d53,'where':_0x16e931,'phone':_0x2cfd59}))[_0x7206('0x1d')](function(_0x581584){_0x2e4a27=_0x581584;if(!_[_0x7206('0x1e')](_0x2e4a27)){if(_0x2e4a27[_0x7206('0x1f')]===0x1){_0x5c4362=_0x2e4a27[0x0];logger[_0x7206('0x20')](_0x7206('0x21'),_0xbca8b7[_0x7206('0x22')],_0x15eab9['id'],_0x5c4362['id']);}else{logger[_0x7206('0x20')](_0x7206('0x23'),_0xbca8b7[_0x7206('0x22')],_0x15eab9['id'],_[_0x7206('0x13')](_0x2e4a27,'id')[_0x7206('0x24')](','));}return;}else{logger[_0x7206('0x20')](_0x7206('0x25'),_0xbca8b7[_0x7206('0x22')],_0x15eab9['id']);var _0x11fa9={'ListId':_0x277593};var _0x41d5ec=_0x1b6e1f[_0x7206('0x26')]&&_0x1b6e1f[_0x7206('0x26')]!=='0'?_0x1b6e1f[_0x7206('0x26')]:_0x7206('0x12');if(_0x2afd1a){logger['info']('[CM][%s][%s]\x20Autocreate\x20enabled',_0xbca8b7['uniqueid'],_0x15eab9['id']);_0x11fa9[_0x41d5ec]=_[_0x7206('0xc')](_0xbca8b7[_0x7206('0x14')])?_0xbca8b7['calleridnum']:_0xbca8b7[_0x7206('0x15')];if(_[_0x7206('0xc')](_0xbca8b7['routeId'])){_0x11fa9[_0x7206('0x17')]=_0xbca8b7[_0x7206('0x27')]&&_0xbca8b7[_0x7206('0x27')]!==_0x7206('0x28')?_0xbca8b7[_0x7206('0x27')]:'Unknown';}else{_0x11fa9[_0x7206('0x17')]=_0xbca8b7[_0x7206('0x29')]&&_0xbca8b7[_0x7206('0x29')]!==_0x7206('0x28')?_0xbca8b7[_0x7206('0x29')]:_0x7206('0x2a');}return BPromise[_0x7206('0x2b')]()['then'](cmContactRpc['createContact'](_0x11fa9))[_0x7206('0x1d')](function(_0x487300){_0x5c4362=_0x487300;_0x2e4a27['push'](_0x487300);if(_0x5c4362){logger[_0x7206('0x20')](_0x7206('0x2c'),_0xbca8b7[_0x7206('0x22')],_0x15eab9['id'],_0x5c4362['id']);}return;});}else{logger[_0x7206('0x20')]('[CM][%s][%s]\x20Autocreate\x20disabled',_0xbca8b7[_0x7206('0x22')],_0x15eab9['id']);_0x11fa9[_0x41d5ec]=_[_0x7206('0xc')](_0xbca8b7[_0x7206('0x14')])?_0xbca8b7[_0x7206('0x16')]:_0xbca8b7[_0x7206('0x15')];if(_['isNil'](_0xbca8b7[_0x7206('0x14')])){_0x11fa9['firstName']=_0xbca8b7[_0x7206('0x27')]&&_0xbca8b7[_0x7206('0x27')]!==_0x7206('0x28')?_0xbca8b7[_0x7206('0x27')]:'Unknown';}else{_0x11fa9[_0x7206('0x17')]=_0xbca8b7[_0x7206('0x29')]&&_0xbca8b7[_0x7206('0x29')]!==_0x7206('0x28')?_0xbca8b7['destcalleridname']:_0x7206('0x2a');}_0x5c4362=_0x11fa9;_0x2e4a27[_0x7206('0x2d')](_0x11fa9);return;}}})[_0x7206('0x1d')](function(){if(_0x164c54){emit(_0xbca8b7[_0x7206('0x22')],_0x15eab9,util[_0x7206('0x2e')]('user:%s',_0x164c54['name']),util['format'](_0x7206('0x2f'),_0x1b6e1f['action'][_0x7206('0x30')]()),{'evt':_['merge'](_0xbca8b7,{'autoCreate':_0x2afd1a}),'contact':_0x5c4362===undefined?{}:_0x5c4362,'contacts':_0x2e4a27[_0x7206('0x1f')]===0x0?undefined:_0x2e4a27});}});};