Built motion from commit 37e1ed56.|2.6.29
[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 _0x7d6b=['trigger:%s','lodash','bluebird','ioredis','util','../../../../config/environment','../../../../config/logger','trigger','../../rpc/cmContact','redis','localhost','[CM][%s][%s]','stringify','emit','exec','data1','data2','isNil','data5','xmd-contactid','data3','split','map','routeId','destcalleridnum','calleridnum','firstName','lastName','phone','mobile','fax','ListId','createdAt','scheduledAt','updatedAt','resolve','then','getContacts','isEmpty','length','uniqueid','[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]','join','info','[CM][%s][%s]\x20Contact\x20not\x20found','data4','calleridname','<unknown>','Unknown','destcalleridname','createContact','[CM][%s][%s]\x20Contact\x20created:%s','[CM][%s][%s]\x20Autocreate\x20disabled','format'];(function(_0x1928c9,_0x13a6d1){var _0x51b5fb=function(_0x24cf70){while(--_0x24cf70){_0x1928c9['push'](_0x1928c9['shift']());}};_0x51b5fb(++_0x13a6d1);}(_0x7d6b,0x17b));var _0xb7d6=function(_0x3a6a0b,_0x4d4b97){_0x3a6a0b=_0x3a6a0b-0x0;var _0x2aef81=_0x7d6b[_0x3a6a0b];return _0x2aef81;};'use strict';var _=require(_0xb7d6('0x0'));var BPromise=require(_0xb7d6('0x1'));var Redis=require(_0xb7d6('0x2'));var util=require(_0xb7d6('0x3'));var config=require(_0xb7d6('0x4'));var logger=require(_0xb7d6('0x5'))(_0xb7d6('0x6'));var cmContactRpc=require(_0xb7d6('0x7'));config[_0xb7d6('0x8')]=_['defaults'](config['redis'],{'host':_0xb7d6('0x9'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xb7d6('0x8')]));function emit(_0x144c19,_0x4b7e2d,_0x14c427,_0x1ccdbd,_0xb167b9){logger['info'](_0xb7d6('0xa'),_0x144c19,_0x4b7e2d['id'],_0x14c427,_0x1ccdbd,JSON[_0xb7d6('0xb')](_0xb167b9));io['to'](_0x14c427)[_0xb7d6('0xc')](_0x1ccdbd,_0xb167b9);}exports[_0xb7d6('0xd')]=function(_0xe73252,_0xe497bb,_0x6c1e2a,_0x1f457e){var _0x1f6931,_0x20cdbd;var _0x1f077d={};var _0x3aaa14;var _0x3f9d7c=Number(_0x6c1e2a[_0xb7d6('0xe')]);var _0x5c518d=_0x6c1e2a[_0xb7d6('0xf')]?Boolean(Number(_0x6c1e2a[_0xb7d6('0xf')])):![];var _0x3e25c7;var _0x19a6fc=![];if(!_[_0xb7d6('0x10')](_0x6c1e2a[_0xb7d6('0x11')])){if(_0x6c1e2a[_0xb7d6('0x11')]=='1')_0x19a6fc=!![];}if(!_0x19a6fc){if(_0x1f457e['xmd-contactid']){_0x1f077d['id']=_0x1f457e[_0xb7d6('0x12')];}}if(!_0x1f077d['id']){_0x1f077d['ListId']=_0x3f9d7c;_0x3e25c7=_0x6c1e2a[_0xb7d6('0x13')]&&_0x6c1e2a[_0xb7d6('0x13')]!=='0'?_0x6c1e2a[_0xb7d6('0x13')][_0xb7d6('0x14')](','):['phone'];_0x1f077d['$or']=_[_0xb7d6('0x15')](_0x3e25c7,function(_0x57e910){var _0x34426d={};_0x34426d[_0x57e910]=_0x1f457e[_0xb7d6('0x16')]?_0x1f457e[_0xb7d6('0x17')]:_0x1f457e[_0xb7d6('0x18')];return _0x34426d;});_0x3aaa14=_0x1f457e[_0xb7d6('0x16')]?_0x1f457e[_0xb7d6('0x17')]:_0x1f457e[_0xb7d6('0x18')];}var _0x13b6e4=['id',_0xb7d6('0x19'),_0xb7d6('0x1a'),_0xb7d6('0x1b'),_0xb7d6('0x1c'),_0xb7d6('0x1d'),_0xb7d6('0x1e'),_0xb7d6('0x1f'),_0xb7d6('0x20'),_0xb7d6('0x21')];var _0x131e67=_['union'](_0x13b6e4,_0x3e25c7);BPromise[_0xb7d6('0x22')]()[_0xb7d6('0x23')](cmContactRpc[_0xb7d6('0x24')]({'attributes':_0x131e67,'where':_0x1f077d,'phone':_0x3aaa14}))[_0xb7d6('0x23')](function(_0x39e5c2){_0x20cdbd=_0x39e5c2;if(!_[_0xb7d6('0x25')](_0x20cdbd)){if(_0x20cdbd[_0xb7d6('0x26')]===0x1){_0x1f6931=_0x20cdbd[0x0];logger['info']('[CM][%s][%s]\x20Contact\x20found:%s',_0x1f457e[_0xb7d6('0x27')],_0xe497bb['id'],_0x1f6931['id']);}else{logger['info'](_0xb7d6('0x28'),_0x1f457e[_0xb7d6('0x27')],_0xe497bb['id'],_[_0xb7d6('0x15')](_0x20cdbd,'id')[_0xb7d6('0x29')](','));}return;}else{logger[_0xb7d6('0x2a')](_0xb7d6('0x2b'),_0x1f457e['uniqueid'],_0xe497bb['id']);var _0x1df4c8={'ListId':_0x3f9d7c};var _0x5c4811=_0x6c1e2a['data4']&&_0x6c1e2a[_0xb7d6('0x2c')]!=='0'?_0x6c1e2a['data4']:_0xb7d6('0x1b');if(_0x5c518d){logger['info']('[CM][%s][%s]\x20Autocreate\x20enabled',_0x1f457e[_0xb7d6('0x27')],_0xe497bb['id']);_0x1df4c8[_0x5c4811]=_[_0xb7d6('0x10')](_0x1f457e[_0xb7d6('0x16')])?_0x1f457e[_0xb7d6('0x18')]:_0x1f457e[_0xb7d6('0x17')];if(_[_0xb7d6('0x10')](_0x1f457e[_0xb7d6('0x16')])){_0x1df4c8[_0xb7d6('0x19')]=_0x1f457e['calleridname']&&_0x1f457e[_0xb7d6('0x2d')]!==_0xb7d6('0x2e')?_0x1f457e[_0xb7d6('0x2d')]:_0xb7d6('0x2f');}else{_0x1df4c8['firstName']=_0x1f457e[_0xb7d6('0x30')]&&_0x1f457e[_0xb7d6('0x30')]!==_0xb7d6('0x2e')?_0x1f457e[_0xb7d6('0x30')]:_0xb7d6('0x2f');}return BPromise[_0xb7d6('0x22')]()[_0xb7d6('0x23')](cmContactRpc[_0xb7d6('0x31')](_0x1df4c8))[_0xb7d6('0x23')](function(_0x1a2a3d){_0x1f6931=_0x1a2a3d;_0x20cdbd['push'](_0x1a2a3d);if(_0x1f6931){logger[_0xb7d6('0x2a')](_0xb7d6('0x32'),_0x1f457e['uniqueid'],_0xe497bb['id'],_0x1f6931['id']);}return;});}else{logger[_0xb7d6('0x2a')](_0xb7d6('0x33'),_0x1f457e[_0xb7d6('0x27')],_0xe497bb['id']);_0x1df4c8[_0x5c4811]=_[_0xb7d6('0x10')](_0x1f457e[_0xb7d6('0x16')])?_0x1f457e[_0xb7d6('0x18')]:_0x1f457e['destcalleridnum'];if(_[_0xb7d6('0x10')](_0x1f457e[_0xb7d6('0x16')])){_0x1df4c8['firstName']=_0x1f457e[_0xb7d6('0x2d')]&&_0x1f457e['calleridname']!==_0xb7d6('0x2e')?_0x1f457e[_0xb7d6('0x2d')]:'Unknown';}else{_0x1df4c8[_0xb7d6('0x19')]=_0x1f457e['destcalleridname']&&_0x1f457e[_0xb7d6('0x30')]!==_0xb7d6('0x2e')?_0x1f457e[_0xb7d6('0x30')]:_0xb7d6('0x2f');}_0x1f6931=_0x1df4c8;_0x20cdbd['push'](_0x1df4c8);return;}}})[_0xb7d6('0x23')](function(){if(_0xe73252){emit(_0x1f457e['uniqueid'],_0xe497bb,util[_0xb7d6('0x34')]('user:%s',_0xe73252['name']),util['format'](_0xb7d6('0x35'),_0x6c1e2a['action']['toLowerCase']()),{'evt':_['merge'](_0x1f457e,{'autoCreate':_0x5c518d}),'contact':_0x1f6931===undefined?{}:_0x1f6931,'contacts':_0x20cdbd[_0xb7d6('0x26')]===0x0?undefined:_0x20cdbd});}});};