4cc6624a8953d004f393b22d7131ba1b4514297c
[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 _0xf4b9=['then','[%s][%s]\x20Contact\x20found:%s','format','user:%s','name','trigger:%s','toLowerCase','createContact','[%s][%s]\x20Contact\x20created:%s','xmd-contactid2','action','merge','catch','error','[%s][%s]\x20Error\x20creating\x20contact','[%s][%s]\x20Autocreate\x20disabled','util','lodash','../../../../config/environment','../../../../config/logger','../../rpc/cmContact','defaults','redis','socket.io-emitter','info','[%s][%s]','stringify','emit','exec','autoCreate','data2','data1','calleridnum','isNil','calleridname','<unknown>','uniqueid','firstName','destcalleridname','destcalleridnum','phone','showContact','omit'];(function(_0x4a15e2,_0x4816fc){var _0x243935=function(_0x2e252d){while(--_0x2e252d){_0x4a15e2['push'](_0x4a15e2['shift']());}};_0x243935(++_0x4816fc);}(_0xf4b9,0xbc));var _0x9f4b=function(_0xd0b415,_0x149675){_0xd0b415=_0xd0b415-0x0;var _0x2bdf2c=_0xf4b9[_0xd0b415];return _0x2bdf2c;};'use strict';var BPromise=require('bluebird');var util=require(_0x9f4b('0x0'));var _=require(_0x9f4b('0x1'));var Redis=require('ioredis');var config=require(_0x9f4b('0x2'));var logger=require(_0x9f4b('0x3'))('trigger');var cmContactRpc=require(_0x9f4b('0x4'));config['redis']=_[_0x9f4b('0x5')](config[_0x9f4b('0x6')],{'host':'localhost','port':0x18eb});var io=require(_0x9f4b('0x7'))(new Redis(config[_0x9f4b('0x6')]));function emit(_0x38f3cb,_0x95d27a,_0x4c0a1c,_0x12ce7){logger[_0x9f4b('0x8')](_0x9f4b('0x9'),_0x38f3cb,'',_0x95d27a,_0x4c0a1c,JSON[_0x9f4b('0xa')](_0x12ce7));io['to'](_0x95d27a)[_0x9f4b('0xb')](_0x4c0a1c,_0x12ce7);}exports[_0x9f4b('0xc')]=function(_0xa8bb9f,_0x503f93,_0x4558af){_0x4558af[_0x9f4b('0xd')]=0x0;if(_0x503f93[_0x9f4b('0xe')]&&parseInt(_0x503f93[_0x9f4b('0xe')],0xa)){var _0x3b7941={'ListId':parseInt(_0x503f93[_0x9f4b('0xf')],0xa),'phone':_0x4558af[_0x9f4b('0x10')]};if(_[_0x9f4b('0x11')](_0x4558af['routeId'])){_0x3b7941['firstName']=_0x4558af['calleridname']&&_0x4558af[_0x9f4b('0x12')]!==_0x9f4b('0x13')?_0x4558af[_0x9f4b('0x12')]:_0x4558af[_0x9f4b('0x10')]||_0x4558af[_0x9f4b('0x14')];}else{_0x3b7941[_0x9f4b('0x15')]=_0x4558af[_0x9f4b('0x16')]&&_0x4558af[_0x9f4b('0x16')]!==_0x9f4b('0x13')?_0x4558af[_0x9f4b('0x16')]:_0x4558af[_0x9f4b('0x17')]||_0x4558af['uniqueid'];_0x3b7941[_0x9f4b('0x18')]=_0x4558af[_0x9f4b('0x16')]&&_0x4558af[_0x9f4b('0x16')]!==_0x9f4b('0x13')?_0x4558af['destcalleridname']:_0x4558af[_0x9f4b('0x17')]||_0x4558af['uniqueid'];}BPromise['resolve']()['then'](cmContactRpc[_0x9f4b('0x19')]({'where':_[_0x9f4b('0x1a')](_0x3b7941,[_0x9f4b('0x15')])}))[_0x9f4b('0x1b')](function(_0x303fe0){if(_0x303fe0){logger['info'](_0x9f4b('0x1c'),_0x4558af['uniqueid'],'',_0x303fe0['id']);if(_0xa8bb9f){_0x4558af['xmd-contactid2']=_0x303fe0['id'];emit(_0x4558af[_0x9f4b('0x14')],util[_0x9f4b('0x1d')](_0x9f4b('0x1e'),_0xa8bb9f[_0x9f4b('0x1f')]),util[_0x9f4b('0x1d')](_0x9f4b('0x20'),_0x503f93['action'][_0x9f4b('0x21')]()),_['merge'](_0x4558af,{'ListId':parseInt(_0x503f93[_0x9f4b('0xf')],0xa)}));}return;}else{logger['info']('[%s][%s]\x20Contact\x20not\x20found',_0x4558af[_0x9f4b('0x14')],'');return BPromise['resolve']()['then'](cmContactRpc[_0x9f4b('0x22')](_0x3b7941));}})['then'](function(_0x38ec55){if(_0x38ec55){logger[_0x9f4b('0x8')](_0x9f4b('0x23'),_0x4558af[_0x9f4b('0x14')],'',_0x38ec55['id']);if(_0xa8bb9f){_0x4558af[_0x9f4b('0x24')]=_0x38ec55['id'];emit(_0x4558af['uniqueid'],util[_0x9f4b('0x1d')](_0x9f4b('0x1e'),_0xa8bb9f[_0x9f4b('0x1f')]),util['format'](_0x9f4b('0x20'),_0x503f93[_0x9f4b('0x25')][_0x9f4b('0x21')]()),_[_0x9f4b('0x26')](_0x4558af,{'ListId':parseInt(_0x503f93[_0x9f4b('0xf')],0xa)}));}}})[_0x9f4b('0x27')](function(_0x3ad0f8){logger[_0x9f4b('0x28')](_0x9f4b('0x29'),_0x4558af['uniqueid'],'',JSON[_0x9f4b('0xa')](_0x3ad0f8));});}else{if(_0xa8bb9f){logger[_0x9f4b('0x8')](_0x9f4b('0x2a'),_0x4558af[_0x9f4b('0x14')],'');emit(_0x4558af[_0x9f4b('0x14')],util[_0x9f4b('0x1d')](_0x9f4b('0x1e'),_0xa8bb9f['name']),util[_0x9f4b('0x1d')](_0x9f4b('0x20'),_0x503f93[_0x9f4b('0x25')][_0x9f4b('0x21')]()),_['merge']({'ListId':parseInt(_0x503f93['data1'],0xa)},_0x4558af));}}};