Built motion from commit (unavailable).|2.5.21
[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 _0xa778=['$or','destcalleridnum','calleridnum','firstName','mobile','fax','createdAt','scheduledAt','resolve','getContacts','then','isEmpty','length','[CM][%s][%s]\x20Contact\x20found:%s','[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]','uniqueid','map','join','[CM][%s][%s]\x20Contact\x20not\x20found','data4','isNil','routeId','calleridname','<unknown>','Unknown','destcalleridname','createContact','push','[CM][%s][%s]\x20Contact\x20created:%s','[CM][%s][%s]\x20Autocreate\x20disabled','format','user:%s','name','trigger:%s','toLowerCase','merge','lodash','bluebird','util','../../../../config/environment','trigger','../../rpc/cmContact','redis','localhost','socket.io-emitter','info','stringify','exec','data1','data2','xmd-contactid','ListId','data3','split','phone'];(function(_0x546bc6,_0x37de92){var _0x249604=function(_0x97a8a0){while(--_0x97a8a0){_0x546bc6['push'](_0x546bc6['shift']());}};_0x249604(++_0x37de92);}(_0xa778,0x137));var _0x8a77=function(_0x37281c,_0x22fc8c){_0x37281c=_0x37281c-0x0;var _0x64ce4c=_0xa778[_0x37281c];return _0x64ce4c;};'use strict';var _=require(_0x8a77('0x0'));var BPromise=require(_0x8a77('0x1'));var Redis=require('ioredis');var util=require(_0x8a77('0x2'));var config=require(_0x8a77('0x3'));var logger=require('../../../../config/logger')(_0x8a77('0x4'));var cmContactRpc=require(_0x8a77('0x5'));config[_0x8a77('0x6')]=_['defaults'](config[_0x8a77('0x6')],{'host':_0x8a77('0x7'),'port':0x18eb});var io=require(_0x8a77('0x8'))(new Redis(config[_0x8a77('0x6')]));function emit(_0x465e70,_0x132618,_0x52f514,_0x427492,_0x56108f){logger[_0x8a77('0x9')]('[CM][%s][%s]',_0x465e70,_0x132618['id'],_0x52f514,_0x427492,JSON[_0x8a77('0xa')](_0x56108f));io['to'](_0x52f514)['emit'](_0x427492,_0x56108f);}exports[_0x8a77('0xb')]=function(_0x105aa8,_0x5afe82,_0x5d1d79,_0x540f64){var _0x452918,_0x3ec9f5;var _0x2acfc1={};var _0x1fcbdc=Number(_0x5d1d79[_0x8a77('0xc')]);var _0x5d9c88=_0x5d1d79[_0x8a77('0xd')]?Boolean(Number(_0x5d1d79[_0x8a77('0xd')])):![];var _0x42a24a;if(_0x540f64[_0x8a77('0xe')]){_0x2acfc1['id']=_0x540f64[_0x8a77('0xe')];}if(!_0x2acfc1['id']){_0x2acfc1[_0x8a77('0xf')]=_0x1fcbdc;_0x42a24a=_0x5d1d79[_0x8a77('0x10')]&&_0x5d1d79[_0x8a77('0x10')]!=='0'?_0x5d1d79[_0x8a77('0x10')][_0x8a77('0x11')](','):[_0x8a77('0x12')];_0x2acfc1[_0x8a77('0x13')]=_['map'](_0x42a24a,function(_0x4b91a3){var _0x304495={};_0x304495[_0x4b91a3]=_0x540f64['routeId']?_0x540f64[_0x8a77('0x14')]:_0x540f64[_0x8a77('0x15')];return _0x304495;});}var _0xa74378=['id',_0x8a77('0x16'),'lastName',_0x8a77('0x12'),_0x8a77('0x17'),_0x8a77('0x18'),_0x8a77('0xf'),_0x8a77('0x19'),_0x8a77('0x1a'),'updatedAt'];var _0x4d881e=_['union'](_0xa74378,_0x42a24a);BPromise[_0x8a77('0x1b')]()['then'](cmContactRpc[_0x8a77('0x1c')]({'attributes':_0x4d881e,'where':_0x2acfc1}))[_0x8a77('0x1d')](function(_0x2004c8){_0x3ec9f5=_0x2004c8;if(!_[_0x8a77('0x1e')](_0x3ec9f5)){if(_0x3ec9f5[_0x8a77('0x1f')]===0x1){_0x452918=_0x3ec9f5[0x0];logger[_0x8a77('0x9')](_0x8a77('0x20'),_0x540f64['uniqueid'],_0x5afe82['id'],_0x452918['id']);}else{logger[_0x8a77('0x9')](_0x8a77('0x21'),_0x540f64[_0x8a77('0x22')],_0x5afe82['id'],_[_0x8a77('0x23')](_0x3ec9f5,'id')[_0x8a77('0x24')](','));}return;}else{logger[_0x8a77('0x9')](_0x8a77('0x25'),_0x540f64[_0x8a77('0x22')],_0x5afe82['id']);var _0x26b239={'ListId':_0x1fcbdc};var _0xe0a78c=_0x5d1d79['data4']&&_0x5d1d79[_0x8a77('0x26')]!=='0'?_0x5d1d79[_0x8a77('0x26')]:_0x8a77('0x12');if(_0x5d9c88){logger[_0x8a77('0x9')]('[CM][%s][%s]\x20Autocreate\x20enabled',_0x540f64[_0x8a77('0x22')],_0x5afe82['id']);_0x26b239[_0xe0a78c]=_[_0x8a77('0x27')](_0x540f64[_0x8a77('0x28')])?_0x540f64['calleridnum']:_0x540f64['destcalleridnum'];if(_['isNil'](_0x540f64[_0x8a77('0x28')])){_0x26b239[_0x8a77('0x16')]=_0x540f64[_0x8a77('0x29')]&&_0x540f64[_0x8a77('0x29')]!==_0x8a77('0x2a')?_0x540f64[_0x8a77('0x29')]:_0x8a77('0x2b');}else{_0x26b239[_0x8a77('0x16')]=_0x540f64[_0x8a77('0x2c')]&&_0x540f64[_0x8a77('0x2c')]!==_0x8a77('0x2a')?_0x540f64[_0x8a77('0x2c')]:_0x8a77('0x2b');}return BPromise[_0x8a77('0x1b')]()['then'](cmContactRpc[_0x8a77('0x2d')](_0x26b239))[_0x8a77('0x1d')](function(_0xf46b9b){_0x452918=_0xf46b9b;_0x3ec9f5[_0x8a77('0x2e')](_0xf46b9b);if(_0x452918){logger[_0x8a77('0x9')](_0x8a77('0x2f'),_0x540f64[_0x8a77('0x22')],_0x5afe82['id'],_0x452918['id']);}return;});}else{logger[_0x8a77('0x9')](_0x8a77('0x30'),_0x540f64[_0x8a77('0x22')],_0x5afe82['id']);_0x26b239[_0xe0a78c]=_[_0x8a77('0x27')](_0x540f64[_0x8a77('0x28')])?_0x540f64[_0x8a77('0x15')]:_0x540f64['destcalleridnum'];if(_['isNil'](_0x540f64[_0x8a77('0x28')])){_0x26b239[_0x8a77('0x16')]=_0x540f64[_0x8a77('0x29')]&&_0x540f64[_0x8a77('0x29')]!==_0x8a77('0x2a')?_0x540f64['calleridname']:_0x8a77('0x2b');}else{_0x26b239[_0x8a77('0x16')]=_0x540f64[_0x8a77('0x2c')]&&_0x540f64['destcalleridname']!==_0x8a77('0x2a')?_0x540f64[_0x8a77('0x2c')]:_0x8a77('0x2b');}_0x452918=_0x26b239;_0x3ec9f5[_0x8a77('0x2e')](_0x26b239);return;}}})[_0x8a77('0x1d')](function(){if(_0x105aa8){emit(_0x540f64['uniqueid'],_0x5afe82,util[_0x8a77('0x31')](_0x8a77('0x32'),_0x105aa8[_0x8a77('0x33')]),util['format'](_0x8a77('0x34'),_0x5d1d79['action'][_0x8a77('0x35')]()),{'evt':_[_0x8a77('0x36')](_0x540f64,{'autoCreate':_0x5d9c88}),'contact':_0x452918===undefined?{}:_0x452918,'contacts':_0x3ec9f5[_0x8a77('0x1f')]===0x0?undefined:_0x3ec9f5});}});};