e40c4c2a7bc0ac8971208c3649bc184105a7ea8f
[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 _0x7f18=['destcalleridname','resolve','createContact','push','[CM][%s][%s]\x20Contact\x20created:%s','format','user:%s','name','trigger:%s','merge','lodash','ioredis','util','../../../../config/logger','trigger','../../rpc/cmContact','redis','defaults','socket.io-emitter','info','[CM][%s][%s]','exec','data2','xmd-contactid','ListId','data3','split','phone','$or','routeId','destcalleridnum','calleridnum','firstName','lastName','mobile','fax','createdAt','scheduledAt','updatedAt','union','then','getContacts','length','[CM][%s][%s]\x20Contact\x20found:%s','map','join','[CM][%s][%s]\x20Contact\x20not\x20found','data4','[CM][%s][%s]\x20Autocreate\x20enabled','uniqueid','isNil','calleridname','<unknown>','Unknown'];(function(_0x29dfa5,_0xd3078e){var _0x41c15a=function(_0x10802b){while(--_0x10802b){_0x29dfa5['push'](_0x29dfa5['shift']());}};_0x41c15a(++_0xd3078e);}(_0x7f18,0x14e));var _0x87f1=function(_0x37e845,_0x219f9f){_0x37e845=_0x37e845-0x0;var _0x59e55b=_0x7f18[_0x37e845];return _0x59e55b;};'use strict';var _=require(_0x87f1('0x0'));var BPromise=require('bluebird');var Redis=require(_0x87f1('0x1'));var util=require(_0x87f1('0x2'));var config=require('../../../../config/environment');var logger=require(_0x87f1('0x3'))(_0x87f1('0x4'));var cmContactRpc=require(_0x87f1('0x5'));config[_0x87f1('0x6')]=_[_0x87f1('0x7')](config[_0x87f1('0x6')],{'host':'localhost','port':0x18eb});var io=require(_0x87f1('0x8'))(new Redis(config[_0x87f1('0x6')]));function emit(_0x3319b1,_0x1e5547,_0x21622c,_0x38aa63,_0x4ef855){logger[_0x87f1('0x9')](_0x87f1('0xa'),_0x3319b1,_0x1e5547['id'],_0x21622c,_0x38aa63,JSON['stringify'](_0x4ef855));io['to'](_0x21622c)['emit'](_0x38aa63,_0x4ef855);}exports[_0x87f1('0xb')]=function(_0x52833f,_0x47164a,_0x2a27d3,_0x38b76f){var _0x1b4e07,_0x555560;var _0x1953c6={};var _0x37198e=Number(_0x2a27d3['data1']);var _0x1b8b7c=_0x2a27d3[_0x87f1('0xc')]?Boolean(Number(_0x2a27d3[_0x87f1('0xc')])):![];var _0x10ee91;if(_0x38b76f[_0x87f1('0xd')]){_0x1953c6['id']=_0x38b76f[_0x87f1('0xd')];}if(!_0x1953c6['id']){_0x1953c6[_0x87f1('0xe')]=_0x37198e;_0x10ee91=_0x2a27d3[_0x87f1('0xf')]&&_0x2a27d3['data3']!=='0'?_0x2a27d3[_0x87f1('0xf')][_0x87f1('0x10')](','):[_0x87f1('0x11')];_0x1953c6[_0x87f1('0x12')]=_['map'](_0x10ee91,function(_0x354584){var _0x4d4c85={};_0x4d4c85[_0x354584]=_0x38b76f[_0x87f1('0x13')]?_0x38b76f[_0x87f1('0x14')]:_0x38b76f[_0x87f1('0x15')];return _0x4d4c85;});}var _0x938d18=['id',_0x87f1('0x16'),_0x87f1('0x17'),_0x87f1('0x11'),_0x87f1('0x18'),_0x87f1('0x19'),_0x87f1('0xe'),_0x87f1('0x1a'),_0x87f1('0x1b'),_0x87f1('0x1c')];var _0x59aa8d=_[_0x87f1('0x1d')](_0x938d18,_0x10ee91);BPromise['resolve']()[_0x87f1('0x1e')](cmContactRpc[_0x87f1('0x1f')]({'attributes':_0x59aa8d,'where':_0x1953c6}))[_0x87f1('0x1e')](function(_0x57ad6e){_0x555560=_0x57ad6e;if(!_['isEmpty'](_0x555560)){if(_0x555560[_0x87f1('0x20')]===0x1){_0x1b4e07=_0x555560[0x0];logger[_0x87f1('0x9')](_0x87f1('0x21'),_0x38b76f['uniqueid'],_0x47164a['id'],_0x1b4e07['id']);}else{logger['info']('[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]',_0x38b76f['uniqueid'],_0x47164a['id'],_[_0x87f1('0x22')](_0x555560,'id')[_0x87f1('0x23')](','));}return;}else{logger[_0x87f1('0x9')](_0x87f1('0x24'),_0x38b76f['uniqueid'],_0x47164a['id']);var _0x5a5e8c={'ListId':_0x37198e};var _0xee1945=_0x2a27d3[_0x87f1('0x25')]&&_0x2a27d3['data4']!=='0'?_0x2a27d3[_0x87f1('0x25')]:_0x87f1('0x11');if(_0x1b8b7c){logger[_0x87f1('0x9')](_0x87f1('0x26'),_0x38b76f[_0x87f1('0x27')],_0x47164a['id']);_0x5a5e8c[_0xee1945]=_[_0x87f1('0x28')](_0x38b76f[_0x87f1('0x13')])?_0x38b76f['calleridnum']:_0x38b76f[_0x87f1('0x14')];if(_[_0x87f1('0x28')](_0x38b76f[_0x87f1('0x13')])){_0x5a5e8c[_0x87f1('0x16')]=_0x38b76f[_0x87f1('0x29')]&&_0x38b76f[_0x87f1('0x29')]!==_0x87f1('0x2a')?_0x38b76f['calleridname']:_0x87f1('0x2b');}else{_0x5a5e8c[_0x87f1('0x16')]=_0x38b76f['destcalleridname']&&_0x38b76f[_0x87f1('0x2c')]!=='<unknown>'?_0x38b76f[_0x87f1('0x2c')]:_0x87f1('0x2b');}return BPromise[_0x87f1('0x2d')]()[_0x87f1('0x1e')](cmContactRpc[_0x87f1('0x2e')](_0x5a5e8c))[_0x87f1('0x1e')](function(_0x273be3){_0x1b4e07=_0x273be3;_0x555560[_0x87f1('0x2f')](_0x273be3);if(_0x1b4e07){logger[_0x87f1('0x9')](_0x87f1('0x30'),_0x38b76f[_0x87f1('0x27')],_0x47164a['id'],_0x1b4e07['id']);}return;});}else{logger[_0x87f1('0x9')]('[CM][%s][%s]\x20Autocreate\x20disabled',_0x38b76f[_0x87f1('0x27')],_0x47164a['id']);_0x5a5e8c[_0xee1945]=_[_0x87f1('0x28')](_0x38b76f['routeId'])?_0x38b76f['calleridnum']:_0x38b76f[_0x87f1('0x14')];if(_['isNil'](_0x38b76f['routeId'])){_0x5a5e8c[_0x87f1('0x16')]=_0x38b76f[_0x87f1('0x29')]&&_0x38b76f[_0x87f1('0x29')]!==_0x87f1('0x2a')?_0x38b76f[_0x87f1('0x29')]:_0x87f1('0x2b');}else{_0x5a5e8c[_0x87f1('0x16')]=_0x38b76f[_0x87f1('0x2c')]&&_0x38b76f['destcalleridname']!=='<unknown>'?_0x38b76f[_0x87f1('0x2c')]:'Unknown';}_0x1b4e07=_0x5a5e8c;_0x555560[_0x87f1('0x2f')](_0x5a5e8c);return;}}})['then'](function(){if(_0x52833f){emit(_0x38b76f[_0x87f1('0x27')],_0x47164a,util[_0x87f1('0x31')](_0x87f1('0x32'),_0x52833f[_0x87f1('0x33')]),util[_0x87f1('0x31')](_0x87f1('0x34'),_0x2a27d3['action']['toLowerCase']()),{'evt':_[_0x87f1('0x35')](_0x38b76f,{'autoCreate':_0x1b8b7c}),'contact':_0x1b4e07===undefined?{}:_0x1b4e07,'contacts':_0x555560[_0x87f1('0x20')]===0x0?undefined:_0x555560});}});};