Built motion from commit (unavailable).|2.5.31
[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 _0x62f8=['format','user:%s','name','action','toLowerCase','merge','lodash','bluebird','ioredis','util','../../../../config/logger','trigger','../../rpc/cmContact','defaults','redis','localhost','socket.io-emitter','[CM][%s][%s]','stringify','emit','exec','data1','data2','xmd-contactid','ListId','data3','$or','map','routeId','destcalleridnum','firstName','lastName','fax','scheduledAt','updatedAt','resolve','then','isEmpty','length','info','[CM][%s][%s]\x20Contact\x20found:%s','join','[CM][%s][%s]\x20Contact\x20not\x20found','uniqueid','data4','phone','[CM][%s][%s]\x20Autocreate\x20enabled','isNil','calleridnum','calleridname','Unknown','destcalleridname','push','[CM][%s][%s]\x20Contact\x20created:%s','[CM][%s][%s]\x20Autocreate\x20disabled','<unknown>'];(function(_0x32827a,_0x4591b3){var _0x2e1a8b=function(_0x180fa2){while(--_0x180fa2){_0x32827a['push'](_0x32827a['shift']());}};_0x2e1a8b(++_0x4591b3);}(_0x62f8,0x18e));var _0x862f=function(_0x88814f,_0x49f6ce){_0x88814f=_0x88814f-0x0;var _0x54554d=_0x62f8[_0x88814f];return _0x54554d;};'use strict';var _=require(_0x862f('0x0'));var BPromise=require(_0x862f('0x1'));var Redis=require(_0x862f('0x2'));var util=require(_0x862f('0x3'));var config=require('../../../../config/environment');var logger=require(_0x862f('0x4'))(_0x862f('0x5'));var cmContactRpc=require(_0x862f('0x6'));config['redis']=_[_0x862f('0x7')](config[_0x862f('0x8')],{'host':_0x862f('0x9'),'port':0x18eb});var io=require(_0x862f('0xa'))(new Redis(config['redis']));function emit(_0x1e988b,_0x1f6ccd,_0x321396,_0x5eb60e,_0x10e906){logger['info'](_0x862f('0xb'),_0x1e988b,_0x1f6ccd['id'],_0x321396,_0x5eb60e,JSON[_0x862f('0xc')](_0x10e906));io['to'](_0x321396)[_0x862f('0xd')](_0x5eb60e,_0x10e906);}exports[_0x862f('0xe')]=function(_0x209848,_0x3e25c4,_0x23f1d1,_0x10976a){var _0xee97e3,_0x575c6e;var _0x11b8e7={};var _0x3715fa=Number(_0x23f1d1[_0x862f('0xf')]);var _0x3d167a=_0x23f1d1[_0x862f('0x10')]?Boolean(Number(_0x23f1d1[_0x862f('0x10')])):![];var _0x4c3063;if(_0x10976a[_0x862f('0x11')]){_0x11b8e7['id']=_0x10976a[_0x862f('0x11')];}if(!_0x11b8e7['id']){_0x11b8e7[_0x862f('0x12')]=_0x3715fa;_0x4c3063=_0x23f1d1['data3']&&_0x23f1d1[_0x862f('0x13')]!=='0'?_0x23f1d1[_0x862f('0x13')]['split'](','):['phone'];_0x11b8e7[_0x862f('0x14')]=_[_0x862f('0x15')](_0x4c3063,function(_0x209cdc){var _0x3c0876={};_0x3c0876[_0x209cdc]=_0x10976a[_0x862f('0x16')]?_0x10976a[_0x862f('0x17')]:_0x10976a['calleridnum'];return _0x3c0876;});}var _0x161914=['id',_0x862f('0x18'),_0x862f('0x19'),'phone','mobile',_0x862f('0x1a'),_0x862f('0x12'),'createdAt',_0x862f('0x1b'),_0x862f('0x1c')];var _0x33615a=_['union'](_0x161914,_0x4c3063);BPromise[_0x862f('0x1d')]()['then'](cmContactRpc['getContacts']({'attributes':_0x33615a,'where':_0x11b8e7}))[_0x862f('0x1e')](function(_0x22c350){_0x575c6e=_0x22c350;if(!_[_0x862f('0x1f')](_0x575c6e)){if(_0x575c6e[_0x862f('0x20')]===0x1){_0xee97e3=_0x575c6e[0x0];logger[_0x862f('0x21')](_0x862f('0x22'),_0x10976a['uniqueid'],_0x3e25c4['id'],_0xee97e3['id']);}else{logger['info']('[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]',_0x10976a['uniqueid'],_0x3e25c4['id'],_['map'](_0x575c6e,'id')[_0x862f('0x23')](','));}return;}else{logger[_0x862f('0x21')](_0x862f('0x24'),_0x10976a[_0x862f('0x25')],_0x3e25c4['id']);var _0x23e2d6={'ListId':_0x3715fa};var _0x2fe031=_0x23f1d1[_0x862f('0x26')]&&_0x23f1d1[_0x862f('0x26')]!=='0'?_0x23f1d1['data4']:_0x862f('0x27');if(_0x3d167a){logger[_0x862f('0x21')](_0x862f('0x28'),_0x10976a[_0x862f('0x25')],_0x3e25c4['id']);_0x23e2d6[_0x2fe031]=_[_0x862f('0x29')](_0x10976a[_0x862f('0x16')])?_0x10976a[_0x862f('0x2a')]:_0x10976a[_0x862f('0x17')];if(_[_0x862f('0x29')](_0x10976a[_0x862f('0x16')])){_0x23e2d6[_0x862f('0x18')]=_0x10976a[_0x862f('0x2b')]&&_0x10976a['calleridname']!=='<unknown>'?_0x10976a[_0x862f('0x2b')]:_0x862f('0x2c');}else{_0x23e2d6[_0x862f('0x18')]=_0x10976a[_0x862f('0x2d')]&&_0x10976a[_0x862f('0x2d')]!=='<unknown>'?_0x10976a[_0x862f('0x2d')]:_0x862f('0x2c');}return BPromise[_0x862f('0x1d')]()[_0x862f('0x1e')](cmContactRpc['createContact'](_0x23e2d6))[_0x862f('0x1e')](function(_0x336dec){_0xee97e3=_0x336dec;_0x575c6e[_0x862f('0x2e')](_0x336dec);if(_0xee97e3){logger[_0x862f('0x21')](_0x862f('0x2f'),_0x10976a[_0x862f('0x25')],_0x3e25c4['id'],_0xee97e3['id']);}return;});}else{logger[_0x862f('0x21')](_0x862f('0x30'),_0x10976a['uniqueid'],_0x3e25c4['id']);_0x23e2d6[_0x2fe031]=_[_0x862f('0x29')](_0x10976a[_0x862f('0x16')])?_0x10976a['calleridnum']:_0x10976a[_0x862f('0x17')];if(_[_0x862f('0x29')](_0x10976a[_0x862f('0x16')])){_0x23e2d6[_0x862f('0x18')]=_0x10976a[_0x862f('0x2b')]&&_0x10976a[_0x862f('0x2b')]!==_0x862f('0x31')?_0x10976a[_0x862f('0x2b')]:_0x862f('0x2c');}else{_0x23e2d6[_0x862f('0x18')]=_0x10976a[_0x862f('0x2d')]&&_0x10976a[_0x862f('0x2d')]!==_0x862f('0x31')?_0x10976a[_0x862f('0x2d')]:_0x862f('0x2c');}_0xee97e3=_0x23e2d6;_0x575c6e['push'](_0x23e2d6);return;}}})['then'](function(){if(_0x209848){emit(_0x10976a['uniqueid'],_0x3e25c4,util[_0x862f('0x32')](_0x862f('0x33'),_0x209848[_0x862f('0x34')]),util[_0x862f('0x32')]('trigger:%s',_0x23f1d1[_0x862f('0x35')][_0x862f('0x36')]()),{'evt':_[_0x862f('0x37')](_0x10976a,{'autoCreate':_0x3d167a}),'contact':_0xee97e3===undefined?{}:_0xee97e3,'contacts':_0x575c6e[_0x862f('0x20')]===0x0?undefined:_0x575c6e});}});};