Built motion from commit (unavailable).|2.5.2
[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 _0x9790=['resolve','then','showContact','omit','[%s][%s]\x20Contact\x20found:%s','xmd-contactid2','format','user:%s','name','trigger:%s','toLowerCase','merge','[%s][%s]\x20Contact\x20not\x20found','createContact','[%s][%s]\x20Contact\x20created:%s','action','data1','catch','error','[%s][%s]\x20Error\x20creating\x20contact','[%s][%s]\x20Autocreate\x20disabled','bluebird','util','../../../../config/environment','../../../../config/logger','trigger','redis','localhost','socket.io-emitter','info','[%s][%s]','stringify','exec','autoCreate','data2','calleridnum','routeId','firstName','calleridname','destcalleridname','<unknown>','uniqueid','phone'];(function(_0x11f87d,_0xccba15){var _0x532fd7=function(_0xfef65c){while(--_0xfef65c){_0x11f87d['push'](_0x11f87d['shift']());}};_0x532fd7(++_0xccba15);}(_0x9790,0xc1));var _0x0979=function(_0x1c610f,_0x1c4c51){_0x1c610f=_0x1c610f-0x0;var _0x21e0a0=_0x9790[_0x1c610f];return _0x21e0a0;};'use strict';var BPromise=require(_0x0979('0x0'));var util=require(_0x0979('0x1'));var _=require('lodash');var Redis=require('ioredis');var config=require(_0x0979('0x2'));var logger=require(_0x0979('0x3'))(_0x0979('0x4'));var cmContactRpc=require('../../rpc/cmContact');config[_0x0979('0x5')]=_['defaults'](config[_0x0979('0x5')],{'host':_0x0979('0x6'),'port':0x18eb});var io=require(_0x0979('0x7'))(new Redis(config['redis']));function emit(_0x1fe6d8,_0x1e1a30,_0x10dce7,_0x30da8d){logger[_0x0979('0x8')](_0x0979('0x9'),_0x1fe6d8,'',_0x1e1a30,_0x10dce7,JSON[_0x0979('0xa')](_0x30da8d));io['to'](_0x1e1a30)['emit'](_0x10dce7,_0x30da8d);}exports[_0x0979('0xb')]=function(_0x48c3df,_0x4d809a,_0x5788a3){_0x5788a3[_0x0979('0xc')]=0x0;if(_0x4d809a[_0x0979('0xd')]&&parseInt(_0x4d809a['data2'],0xa)){var _0x1d798f={'ListId':parseInt(_0x4d809a['data1'],0xa),'phone':_0x5788a3[_0x0979('0xe')]};if(_['isNil'](_0x5788a3[_0x0979('0xf')])){_0x1d798f[_0x0979('0x10')]=_0x5788a3['calleridname']&&_0x5788a3[_0x0979('0x11')]!=='<unknown>'?_0x5788a3[_0x0979('0x11')]:_0x5788a3[_0x0979('0xe')]||_0x5788a3['uniqueid'];}else{_0x1d798f[_0x0979('0x10')]=_0x5788a3[_0x0979('0x12')]&&_0x5788a3['destcalleridname']!==_0x0979('0x13')?_0x5788a3[_0x0979('0x12')]:_0x5788a3['destcalleridnum']||_0x5788a3[_0x0979('0x14')];_0x1d798f[_0x0979('0x15')]=_0x5788a3[_0x0979('0x12')]&&_0x5788a3[_0x0979('0x12')]!==_0x0979('0x13')?_0x5788a3['destcalleridname']:_0x5788a3['destcalleridnum']||_0x5788a3[_0x0979('0x14')];}BPromise[_0x0979('0x16')]()[_0x0979('0x17')](cmContactRpc[_0x0979('0x18')]({'where':_[_0x0979('0x19')](_0x1d798f,[_0x0979('0x10')])}))[_0x0979('0x17')](function(_0x37c8aa){if(_0x37c8aa){logger[_0x0979('0x8')](_0x0979('0x1a'),_0x5788a3[_0x0979('0x14')],'',_0x37c8aa['id']);if(_0x48c3df){_0x5788a3[_0x0979('0x1b')]=_0x37c8aa['id'];emit(_0x5788a3[_0x0979('0x14')],util[_0x0979('0x1c')](_0x0979('0x1d'),_0x48c3df[_0x0979('0x1e')]),util[_0x0979('0x1c')](_0x0979('0x1f'),_0x4d809a['action'][_0x0979('0x20')]()),_[_0x0979('0x21')](_0x5788a3,{'ListId':parseInt(_0x4d809a['data1'],0xa)}));}return;}else{logger[_0x0979('0x8')](_0x0979('0x22'),_0x5788a3[_0x0979('0x14')],'');return BPromise[_0x0979('0x16')]()[_0x0979('0x17')](cmContactRpc[_0x0979('0x23')](_0x1d798f));}})[_0x0979('0x17')](function(_0x380324){if(_0x380324){logger[_0x0979('0x8')](_0x0979('0x24'),_0x5788a3['uniqueid'],'',_0x380324['id']);if(_0x48c3df){_0x5788a3[_0x0979('0x1b')]=_0x380324['id'];emit(_0x5788a3[_0x0979('0x14')],util[_0x0979('0x1c')](_0x0979('0x1d'),_0x48c3df['name']),util[_0x0979('0x1c')](_0x0979('0x1f'),_0x4d809a[_0x0979('0x25')][_0x0979('0x20')]()),_[_0x0979('0x21')](_0x5788a3,{'ListId':parseInt(_0x4d809a[_0x0979('0x26')],0xa)}));}}})[_0x0979('0x27')](function(_0x1c93fd){logger[_0x0979('0x28')](_0x0979('0x29'),_0x5788a3[_0x0979('0x14')],'',JSON[_0x0979('0xa')](_0x1c93fd));});}else{if(_0x48c3df){logger[_0x0979('0x8')](_0x0979('0x2a'),_0x5788a3['uniqueid'],'');emit(_0x5788a3['uniqueid'],util[_0x0979('0x1c')](_0x0979('0x1d'),_0x48c3df[_0x0979('0x1e')]),util[_0x0979('0x1c')](_0x0979('0x1f'),_0x4d809a[_0x0979('0x25')][_0x0979('0x20')]()),_['merge']({'ListId':parseInt(_0x4d809a[_0x0979('0x26')],0xa)},_0x5788a3));}}};