fa921eb3b87434096af48fae84ee596e36d06014
[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 _0xa5cd=['[CM][%s][%s]','stringify','emit','data1','data2','isNil','data5','xmd-contactid','ListId','data3','split','$or','routeId','destcalleridnum','calleridnum','firstName','lastName','phone','mobile','fax','createdAt','scheduledAt','updatedAt','union','then','isEmpty','length','[CM][%s][%s]\x20Contact\x20found:%s','uniqueid','map','join','data4','[CM][%s][%s]\x20Autocreate\x20enabled','calleridname','<unknown>','destcalleridname','Unknown','resolve','createContact','[CM][%s][%s]\x20Contact\x20created:%s','info','push','user:%s','trigger:%s','toLowerCase','merge','ioredis','util','../../../../config/environment','trigger','../../rpc/cmContact','redis','defaults','localhost','socket.io-emitter'];(function(_0x34f3a7,_0x29557e){var _0x499f15=function(_0x5b41a7){while(--_0x5b41a7){_0x34f3a7['push'](_0x34f3a7['shift']());}};_0x499f15(++_0x29557e);}(_0xa5cd,0xd3));var _0xda5c=function(_0x1beef3,_0x57c4b8){_0x1beef3=_0x1beef3-0x0;var _0x5af964=_0xa5cd[_0x1beef3];return _0x5af964;};'use strict';var _=require('lodash');var BPromise=require('bluebird');var Redis=require(_0xda5c('0x0'));var util=require(_0xda5c('0x1'));var config=require(_0xda5c('0x2'));var logger=require('../../../../config/logger')(_0xda5c('0x3'));var cmContactRpc=require(_0xda5c('0x4'));config[_0xda5c('0x5')]=_[_0xda5c('0x6')](config[_0xda5c('0x5')],{'host':_0xda5c('0x7'),'port':0x18eb});var io=require(_0xda5c('0x8'))(new Redis(config['redis']));function emit(_0x7006b3,_0x3c2094,_0x2df01d,_0xa18ef3,_0x4ee173){logger['info'](_0xda5c('0x9'),_0x7006b3,_0x3c2094['id'],_0x2df01d,_0xa18ef3,JSON[_0xda5c('0xa')](_0x4ee173));io['to'](_0x2df01d)[_0xda5c('0xb')](_0xa18ef3,_0x4ee173);}exports['exec']=function(_0x260deb,_0x379589,_0x589607,_0x58711f){var _0x8bcbd4,_0x34fdf4;var _0x19064e={};var _0x4e88da;var _0x365102=Number(_0x589607[_0xda5c('0xc')]);var _0x5bf7b9=_0x589607[_0xda5c('0xd')]?Boolean(Number(_0x589607[_0xda5c('0xd')])):![];var _0x8197a6;var _0x5b5c68=![];if(!_[_0xda5c('0xe')](_0x589607[_0xda5c('0xf')])){if(_0x589607[_0xda5c('0xf')]=='1')_0x5b5c68=!![];}if(!_0x5b5c68){if(_0x58711f[_0xda5c('0x10')]){_0x19064e['id']=_0x58711f['xmd-contactid'];}}if(!_0x19064e['id']){_0x19064e[_0xda5c('0x11')]=_0x365102;_0x8197a6=_0x589607['data3']&&_0x589607[_0xda5c('0x12')]!=='0'?_0x589607['data3'][_0xda5c('0x13')](','):['phone'];_0x19064e[_0xda5c('0x14')]=_['map'](_0x8197a6,function(_0x236ad5){var _0x44dae0={};_0x44dae0[_0x236ad5]=_0x58711f[_0xda5c('0x15')]?_0x58711f[_0xda5c('0x16')]:_0x58711f[_0xda5c('0x17')];return _0x44dae0;});_0x4e88da=_0x58711f['routeId']?_0x58711f[_0xda5c('0x16')]:_0x58711f[_0xda5c('0x17')];}var _0x1ab310=['id',_0xda5c('0x18'),_0xda5c('0x19'),_0xda5c('0x1a'),_0xda5c('0x1b'),_0xda5c('0x1c'),_0xda5c('0x11'),_0xda5c('0x1d'),_0xda5c('0x1e'),_0xda5c('0x1f')];var _0x5dea88=_[_0xda5c('0x20')](_0x1ab310,_0x8197a6);BPromise['resolve']()['then'](cmContactRpc['getContacts']({'attributes':_0x5dea88,'where':_0x19064e,'phone':_0x4e88da}))[_0xda5c('0x21')](function(_0xe03191){_0x34fdf4=_0xe03191;if(!_[_0xda5c('0x22')](_0x34fdf4)){if(_0x34fdf4[_0xda5c('0x23')]===0x1){_0x8bcbd4=_0x34fdf4[0x0];logger['info'](_0xda5c('0x24'),_0x58711f[_0xda5c('0x25')],_0x379589['id'],_0x8bcbd4['id']);}else{logger['info']('[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]',_0x58711f[_0xda5c('0x25')],_0x379589['id'],_[_0xda5c('0x26')](_0x34fdf4,'id')[_0xda5c('0x27')](','));}return;}else{logger['info']('[CM][%s][%s]\x20Contact\x20not\x20found',_0x58711f['uniqueid'],_0x379589['id']);var _0x190a6f={'ListId':_0x365102};var _0x14e06f=_0x589607[_0xda5c('0x28')]&&_0x589607['data4']!=='0'?_0x589607[_0xda5c('0x28')]:_0xda5c('0x1a');if(_0x5bf7b9){logger['info'](_0xda5c('0x29'),_0x58711f[_0xda5c('0x25')],_0x379589['id']);_0x190a6f[_0x14e06f]=_[_0xda5c('0xe')](_0x58711f['routeId'])?_0x58711f[_0xda5c('0x17')]:_0x58711f['destcalleridnum'];if(_[_0xda5c('0xe')](_0x58711f[_0xda5c('0x15')])){_0x190a6f[_0xda5c('0x18')]=_0x58711f[_0xda5c('0x2a')]&&_0x58711f[_0xda5c('0x2a')]!==_0xda5c('0x2b')?_0x58711f[_0xda5c('0x2a')]:'Unknown';}else{_0x190a6f[_0xda5c('0x18')]=_0x58711f[_0xda5c('0x2c')]&&_0x58711f[_0xda5c('0x2c')]!==_0xda5c('0x2b')?_0x58711f[_0xda5c('0x2c')]:_0xda5c('0x2d');}return BPromise[_0xda5c('0x2e')]()[_0xda5c('0x21')](cmContactRpc[_0xda5c('0x2f')](_0x190a6f))[_0xda5c('0x21')](function(_0x235a9f){_0x8bcbd4=_0x235a9f;_0x34fdf4['push'](_0x235a9f);if(_0x8bcbd4){logger['info'](_0xda5c('0x30'),_0x58711f['uniqueid'],_0x379589['id'],_0x8bcbd4['id']);}return;});}else{logger[_0xda5c('0x31')]('[CM][%s][%s]\x20Autocreate\x20disabled',_0x58711f['uniqueid'],_0x379589['id']);_0x190a6f[_0x14e06f]=_[_0xda5c('0xe')](_0x58711f[_0xda5c('0x15')])?_0x58711f['calleridnum']:_0x58711f[_0xda5c('0x16')];if(_[_0xda5c('0xe')](_0x58711f[_0xda5c('0x15')])){_0x190a6f[_0xda5c('0x18')]=_0x58711f[_0xda5c('0x2a')]&&_0x58711f[_0xda5c('0x2a')]!==_0xda5c('0x2b')?_0x58711f['calleridname']:'Unknown';}else{_0x190a6f[_0xda5c('0x18')]=_0x58711f[_0xda5c('0x2c')]&&_0x58711f[_0xda5c('0x2c')]!=='<unknown>'?_0x58711f['destcalleridname']:_0xda5c('0x2d');}_0x8bcbd4=_0x190a6f;_0x34fdf4[_0xda5c('0x32')](_0x190a6f);return;}}})[_0xda5c('0x21')](function(){if(_0x260deb){emit(_0x58711f[_0xda5c('0x25')],_0x379589,util['format'](_0xda5c('0x33'),_0x260deb['name']),util['format'](_0xda5c('0x34'),_0x589607['action'][_0xda5c('0x35')]()),{'evt':_[_0xda5c('0x36')](_0x58711f,{'autoCreate':_0x5bf7b9}),'contact':_0x8bcbd4===undefined?{}:_0x8bcbd4,'contacts':_0x34fdf4['length']===0x0?undefined:_0x34fdf4});}});};