7fb6aef352a66e950be5ae4c4a8ab0317c5ee346
[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 _0x74ae=['resolve','getContacts','then','isEmpty','length','[CM][%s][%s]\x20Contact\x20found:%s','[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]','uniqueid','join','[CM][%s][%s]\x20Contact\x20not\x20found','data4','calleridname','<unknown>','destcalleridname','Unknown','createContact','push','[CM][%s][%s]\x20Contact\x20created:%s','[CM][%s][%s]\x20Autocreate\x20disabled','format','user:%s','name','trigger:%s','action','toLowerCase','merge','lodash','bluebird','util','../../../../config/environment','trigger','../../rpc/cmContact','redis','defaults','localhost','info','[CM][%s][%s]','emit','data2','isNil','xmd-contactid','data3','phone','$or','map','routeId','destcalleridnum','calleridnum','firstName','lastName','mobile','fax','ListId','createdAt','scheduledAt','updatedAt','union'];(function(_0x168c60,_0x539d96){var _0x29bea4=function(_0x1f7f4e){while(--_0x1f7f4e){_0x168c60['push'](_0x168c60['shift']());}};_0x29bea4(++_0x539d96);}(_0x74ae,0xc5));var _0xe74a=function(_0x46f659,_0x3c2c9d){_0x46f659=_0x46f659-0x0;var _0xbf5e5c=_0x74ae[_0x46f659];return _0xbf5e5c;};'use strict';var _=require(_0xe74a('0x0'));var BPromise=require(_0xe74a('0x1'));var Redis=require('ioredis');var util=require(_0xe74a('0x2'));var config=require(_0xe74a('0x3'));var logger=require('../../../../config/logger')(_0xe74a('0x4'));var cmContactRpc=require(_0xe74a('0x5'));config[_0xe74a('0x6')]=_[_0xe74a('0x7')](config[_0xe74a('0x6')],{'host':_0xe74a('0x8'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xe74a('0x6')]));function emit(_0xb3749f,_0x37eaa9,_0xd02dd8,_0x370f05,_0x4ba7c8){logger[_0xe74a('0x9')](_0xe74a('0xa'),_0xb3749f,_0x37eaa9['id'],_0xd02dd8,_0x370f05,JSON['stringify'](_0x4ba7c8));io['to'](_0xd02dd8)[_0xe74a('0xb')](_0x370f05,_0x4ba7c8);}exports['exec']=function(_0x2e9af7,_0x5c12b7,_0x3f46f6,_0x5e112f){var _0x18eff8,_0x5941c7;var _0x2b686d={};var _0x1d1627;var _0x435bfe=Number(_0x3f46f6['data1']);var _0x4dac3f=_0x3f46f6[_0xe74a('0xc')]?Boolean(Number(_0x3f46f6[_0xe74a('0xc')])):![];var _0x4badfe;var _0x49ea3c=![];if(!_[_0xe74a('0xd')](_0x3f46f6['data5'])){if(_0x3f46f6['data5']=='1')_0x49ea3c=!![];}if(!_0x49ea3c){if(_0x5e112f[_0xe74a('0xe')]){_0x2b686d['id']=_0x5e112f['xmd-contactid'];}}if(!_0x2b686d['id']){_0x2b686d['ListId']=_0x435bfe;_0x4badfe=_0x3f46f6[_0xe74a('0xf')]&&_0x3f46f6['data3']!=='0'?_0x3f46f6[_0xe74a('0xf')]['split'](','):[_0xe74a('0x10')];_0x2b686d[_0xe74a('0x11')]=_[_0xe74a('0x12')](_0x4badfe,function(_0x257281){var _0x279326={};_0x279326[_0x257281]=_0x5e112f[_0xe74a('0x13')]?_0x5e112f[_0xe74a('0x14')]:_0x5e112f[_0xe74a('0x15')];return _0x279326;});_0x1d1627=_0x5e112f[_0xe74a('0x13')]?_0x5e112f[_0xe74a('0x14')]:_0x5e112f[_0xe74a('0x15')];}var _0x200c33=['id',_0xe74a('0x16'),_0xe74a('0x17'),_0xe74a('0x10'),_0xe74a('0x18'),_0xe74a('0x19'),_0xe74a('0x1a'),_0xe74a('0x1b'),_0xe74a('0x1c'),_0xe74a('0x1d')];var _0x824be2=_[_0xe74a('0x1e')](_0x200c33,_0x4badfe);BPromise[_0xe74a('0x1f')]()['then'](cmContactRpc[_0xe74a('0x20')]({'attributes':_0x824be2,'where':_0x2b686d,'phone':_0x1d1627}))[_0xe74a('0x21')](function(_0x4be78a){_0x5941c7=_0x4be78a;if(!_[_0xe74a('0x22')](_0x5941c7)){if(_0x5941c7[_0xe74a('0x23')]===0x1){_0x18eff8=_0x5941c7[0x0];logger[_0xe74a('0x9')](_0xe74a('0x24'),_0x5e112f['uniqueid'],_0x5c12b7['id'],_0x18eff8['id']);}else{logger[_0xe74a('0x9')](_0xe74a('0x25'),_0x5e112f[_0xe74a('0x26')],_0x5c12b7['id'],_[_0xe74a('0x12')](_0x5941c7,'id')[_0xe74a('0x27')](','));}return;}else{logger[_0xe74a('0x9')](_0xe74a('0x28'),_0x5e112f[_0xe74a('0x26')],_0x5c12b7['id']);var _0x3124b9={'ListId':_0x435bfe};var _0x1133a8=_0x3f46f6['data4']&&_0x3f46f6[_0xe74a('0x29')]!=='0'?_0x3f46f6[_0xe74a('0x29')]:_0xe74a('0x10');if(_0x4dac3f){logger['info']('[CM][%s][%s]\x20Autocreate\x20enabled',_0x5e112f[_0xe74a('0x26')],_0x5c12b7['id']);_0x3124b9[_0x1133a8]=_[_0xe74a('0xd')](_0x5e112f[_0xe74a('0x13')])?_0x5e112f['calleridnum']:_0x5e112f[_0xe74a('0x14')];if(_[_0xe74a('0xd')](_0x5e112f[_0xe74a('0x13')])){_0x3124b9['firstName']=_0x5e112f[_0xe74a('0x2a')]&&_0x5e112f[_0xe74a('0x2a')]!==_0xe74a('0x2b')?_0x5e112f[_0xe74a('0x2a')]:'Unknown';}else{_0x3124b9['firstName']=_0x5e112f[_0xe74a('0x2c')]&&_0x5e112f['destcalleridname']!==_0xe74a('0x2b')?_0x5e112f[_0xe74a('0x2c')]:_0xe74a('0x2d');}return BPromise['resolve']()[_0xe74a('0x21')](cmContactRpc[_0xe74a('0x2e')](_0x3124b9))[_0xe74a('0x21')](function(_0x5c934a){_0x18eff8=_0x5c934a;_0x5941c7[_0xe74a('0x2f')](_0x5c934a);if(_0x18eff8){logger[_0xe74a('0x9')](_0xe74a('0x30'),_0x5e112f[_0xe74a('0x26')],_0x5c12b7['id'],_0x18eff8['id']);}return;});}else{logger[_0xe74a('0x9')](_0xe74a('0x31'),_0x5e112f[_0xe74a('0x26')],_0x5c12b7['id']);_0x3124b9[_0x1133a8]=_[_0xe74a('0xd')](_0x5e112f[_0xe74a('0x13')])?_0x5e112f[_0xe74a('0x15')]:_0x5e112f[_0xe74a('0x14')];if(_[_0xe74a('0xd')](_0x5e112f[_0xe74a('0x13')])){_0x3124b9[_0xe74a('0x16')]=_0x5e112f['calleridname']&&_0x5e112f[_0xe74a('0x2a')]!==_0xe74a('0x2b')?_0x5e112f['calleridname']:_0xe74a('0x2d');}else{_0x3124b9[_0xe74a('0x16')]=_0x5e112f['destcalleridname']&&_0x5e112f[_0xe74a('0x2c')]!=='<unknown>'?_0x5e112f[_0xe74a('0x2c')]:_0xe74a('0x2d');}_0x18eff8=_0x3124b9;_0x5941c7[_0xe74a('0x2f')](_0x3124b9);return;}}})[_0xe74a('0x21')](function(){if(_0x2e9af7){emit(_0x5e112f['uniqueid'],_0x5c12b7,util[_0xe74a('0x32')](_0xe74a('0x33'),_0x2e9af7[_0xe74a('0x34')]),util[_0xe74a('0x32')](_0xe74a('0x35'),_0x3f46f6[_0xe74a('0x36')][_0xe74a('0x37')]()),{'evt':_[_0xe74a('0x38')](_0x5e112f,{'autoCreate':_0x4dac3f}),'contact':_0x18eff8===undefined?{}:_0x18eff8,'contacts':_0x5941c7[_0xe74a('0x23')]===0x0?undefined:_0x5941c7});}});};