Built motion from commit 7ab0e143.|2.5.49
[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 _0x9f62=['$or','map','destcalleridnum','calleridnum','lastName','fax','createdAt','scheduledAt','updatedAt','resolve','then','isEmpty','length','[CM][%s][%s]\x20Contact\x20found:%s','info','[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]','uniqueid','[CM][%s][%s]\x20Contact\x20not\x20found','data4','routeId','firstName','calleridname','<unknown>','Unknown','destcalleridname','createContact','push','[CM][%s][%s]\x20Autocreate\x20disabled','user:%s','name','format','trigger:%s','toLowerCase','merge','bluebird','util','../../../../config/environment','../../../../config/logger','redis','defaults','localhost','emit','exec','data2','isNil','data5','xmd-contactid','ListId','data3','split','phone'];(function(_0x350277,_0x25d306){var _0x5e418b=function(_0x19c176){while(--_0x19c176){_0x350277['push'](_0x350277['shift']());}};_0x5e418b(++_0x25d306);}(_0x9f62,0x154));var _0x29f6=function(_0x229513,_0x2530d8){_0x229513=_0x229513-0x0;var _0x49b0e9=_0x9f62[_0x229513];return _0x49b0e9;};'use strict';var _=require('lodash');var BPromise=require(_0x29f6('0x0'));var Redis=require('ioredis');var util=require(_0x29f6('0x1'));var config=require(_0x29f6('0x2'));var logger=require(_0x29f6('0x3'))('trigger');var cmContactRpc=require('../../rpc/cmContact');config[_0x29f6('0x4')]=_[_0x29f6('0x5')](config[_0x29f6('0x4')],{'host':_0x29f6('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x29f6('0x4')]));function emit(_0x272876,_0x9a43fe,_0x2ba602,_0x416c6c,_0x5e9945){logger['info']('[CM][%s][%s]',_0x272876,_0x9a43fe['id'],_0x2ba602,_0x416c6c,JSON['stringify'](_0x5e9945));io['to'](_0x2ba602)[_0x29f6('0x7')](_0x416c6c,_0x5e9945);}exports[_0x29f6('0x8')]=function(_0x4fb455,_0x5a0724,_0x29b3f5,_0x442623){var _0x4909e0,_0x17b69c;var _0xfa6765={};var _0x5cf872=Number(_0x29b3f5['data1']);var _0x559585=_0x29b3f5['data2']?Boolean(Number(_0x29b3f5[_0x29f6('0x9')])):![];var _0x55cf4;var _0x189344=![];if(!_[_0x29f6('0xa')](_0x29b3f5[_0x29f6('0xb')])){if(_0x29b3f5[_0x29f6('0xb')]=='1')_0x189344=!![];}if(!_0x189344){if(_0x442623[_0x29f6('0xc')]){_0xfa6765['id']=_0x442623[_0x29f6('0xc')];}}if(!_0xfa6765['id']){_0xfa6765[_0x29f6('0xd')]=_0x5cf872;_0x55cf4=_0x29b3f5[_0x29f6('0xe')]&&_0x29b3f5[_0x29f6('0xe')]!=='0'?_0x29b3f5[_0x29f6('0xe')][_0x29f6('0xf')](','):[_0x29f6('0x10')];_0xfa6765[_0x29f6('0x11')]=_[_0x29f6('0x12')](_0x55cf4,function(_0x3584a1){var _0x5bfda7={};_0x5bfda7[_0x3584a1]=_0x442623['routeId']?_0x442623[_0x29f6('0x13')]:_0x442623[_0x29f6('0x14')];return _0x5bfda7;});}var _0xb31436=['id','firstName',_0x29f6('0x15'),_0x29f6('0x10'),'mobile',_0x29f6('0x16'),_0x29f6('0xd'),_0x29f6('0x17'),_0x29f6('0x18'),_0x29f6('0x19')];var _0x2bfb3d=_['union'](_0xb31436,_0x55cf4);BPromise[_0x29f6('0x1a')]()['then'](cmContactRpc['getContacts']({'attributes':_0x2bfb3d,'where':_0xfa6765}))[_0x29f6('0x1b')](function(_0x1fa159){_0x17b69c=_0x1fa159;if(!_[_0x29f6('0x1c')](_0x17b69c)){if(_0x17b69c[_0x29f6('0x1d')]===0x1){_0x4909e0=_0x17b69c[0x0];logger['info'](_0x29f6('0x1e'),_0x442623['uniqueid'],_0x5a0724['id'],_0x4909e0['id']);}else{logger[_0x29f6('0x1f')](_0x29f6('0x20'),_0x442623[_0x29f6('0x21')],_0x5a0724['id'],_[_0x29f6('0x12')](_0x17b69c,'id')['join'](','));}return;}else{logger[_0x29f6('0x1f')](_0x29f6('0x22'),_0x442623['uniqueid'],_0x5a0724['id']);var _0x1401fb={'ListId':_0x5cf872};var _0x45f792=_0x29b3f5[_0x29f6('0x23')]&&_0x29b3f5[_0x29f6('0x23')]!=='0'?_0x29b3f5[_0x29f6('0x23')]:_0x29f6('0x10');if(_0x559585){logger[_0x29f6('0x1f')]('[CM][%s][%s]\x20Autocreate\x20enabled',_0x442623[_0x29f6('0x21')],_0x5a0724['id']);_0x1401fb[_0x45f792]=_[_0x29f6('0xa')](_0x442623[_0x29f6('0x24')])?_0x442623[_0x29f6('0x14')]:_0x442623[_0x29f6('0x13')];if(_[_0x29f6('0xa')](_0x442623[_0x29f6('0x24')])){_0x1401fb[_0x29f6('0x25')]=_0x442623[_0x29f6('0x26')]&&_0x442623[_0x29f6('0x26')]!==_0x29f6('0x27')?_0x442623[_0x29f6('0x26')]:_0x29f6('0x28');}else{_0x1401fb[_0x29f6('0x25')]=_0x442623[_0x29f6('0x29')]&&_0x442623[_0x29f6('0x29')]!==_0x29f6('0x27')?_0x442623['destcalleridname']:'Unknown';}return BPromise[_0x29f6('0x1a')]()['then'](cmContactRpc[_0x29f6('0x2a')](_0x1401fb))[_0x29f6('0x1b')](function(_0x1e1bb6){_0x4909e0=_0x1e1bb6;_0x17b69c[_0x29f6('0x2b')](_0x1e1bb6);if(_0x4909e0){logger['info']('[CM][%s][%s]\x20Contact\x20created:%s',_0x442623[_0x29f6('0x21')],_0x5a0724['id'],_0x4909e0['id']);}return;});}else{logger[_0x29f6('0x1f')](_0x29f6('0x2c'),_0x442623[_0x29f6('0x21')],_0x5a0724['id']);_0x1401fb[_0x45f792]=_[_0x29f6('0xa')](_0x442623[_0x29f6('0x24')])?_0x442623[_0x29f6('0x14')]:_0x442623[_0x29f6('0x13')];if(_[_0x29f6('0xa')](_0x442623[_0x29f6('0x24')])){_0x1401fb[_0x29f6('0x25')]=_0x442623[_0x29f6('0x26')]&&_0x442623[_0x29f6('0x26')]!==_0x29f6('0x27')?_0x442623['calleridname']:'Unknown';}else{_0x1401fb[_0x29f6('0x25')]=_0x442623[_0x29f6('0x29')]&&_0x442623[_0x29f6('0x29')]!=='<unknown>'?_0x442623[_0x29f6('0x29')]:_0x29f6('0x28');}_0x4909e0=_0x1401fb;_0x17b69c[_0x29f6('0x2b')](_0x1401fb);return;}}})[_0x29f6('0x1b')](function(){if(_0x4fb455){emit(_0x442623[_0x29f6('0x21')],_0x5a0724,util['format'](_0x29f6('0x2d'),_0x4fb455[_0x29f6('0x2e')]),util[_0x29f6('0x2f')](_0x29f6('0x30'),_0x29b3f5['action'][_0x29f6('0x31')]()),{'evt':_[_0x29f6('0x32')](_0x442623,{'autoCreate':_0x559585}),'contact':_0x4909e0===undefined?{}:_0x4909e0,'contacts':_0x17b69c[_0x29f6('0x1d')]===0x0?undefined:_0x17b69c});}});};