Built motion from commit (unavailable).|2.3.4
[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 _0x6bd7=['stringify','emit','exec','autoCreate','data2','data1','isNil','firstName','calleridname','<unknown>','calleridnum','destcalleridname','destcalleridnum','uniqueid','resolve','showContact','omit','then','format','trigger:%s','action','toLowerCase','merge','createContact','xmd-contactid2','name','error','user:%s','bluebird','util','lodash','ioredis','../../../../config/environment','../../../../config/logger','trigger','../../rpc/cmContact','redis','localhost','socket.io-emitter','info'];(function(_0x453862,_0xd3bb4c){var _0x17508a=function(_0x172b7e){while(--_0x172b7e){_0x453862['push'](_0x453862['shift']());}};_0x17508a(++_0xd3bb4c);}(_0x6bd7,0x184));var _0x76bd=function(_0x2a4cc6,_0x3ed438){_0x2a4cc6=_0x2a4cc6-0x0;var _0x381547=_0x6bd7[_0x2a4cc6];return _0x381547;};'use strict';var BPromise=require(_0x76bd('0x0'));var util=require(_0x76bd('0x1'));var _=require(_0x76bd('0x2'));var Redis=require(_0x76bd('0x3'));var config=require(_0x76bd('0x4'));var logger=require(_0x76bd('0x5'))(_0x76bd('0x6'));var cmContactRpc=require(_0x76bd('0x7'));config['redis']=_['defaults'](config[_0x76bd('0x8')],{'host':_0x76bd('0x9'),'port':0x18eb});var io=require(_0x76bd('0xa'))(new Redis(config[_0x76bd('0x8')]));function emit(_0x1e7450,_0x46295a,_0x12446a){logger[_0x76bd('0xb')](_0x1e7450,_0x46295a,JSON[_0x76bd('0xc')](_0x12446a));io['to'](_0x1e7450)[_0x76bd('0xd')](_0x46295a,_0x12446a);}exports[_0x76bd('0xe')]=function(_0xcaad2c,_0x4c16cd,_0x424562){_0x424562[_0x76bd('0xf')]=0x0;if(_0x4c16cd[_0x76bd('0x10')]&&parseInt(_0x4c16cd[_0x76bd('0x10')],0xa)){var _0x2756c8={'ListId':parseInt(_0x4c16cd[_0x76bd('0x11')],0xa),'phone':_0x424562['calleridnum']};if(_[_0x76bd('0x12')](_0x424562['routeId'])){_0x2756c8[_0x76bd('0x13')]=_0x424562[_0x76bd('0x14')]&&_0x424562['calleridname']!==_0x76bd('0x15')?_0x424562[_0x76bd('0x14')]:_0x424562[_0x76bd('0x16')]||_0x424562['uniqueid'];}else{_0x2756c8['firstName']=_0x424562[_0x76bd('0x17')]&&_0x424562[_0x76bd('0x17')]!=='<unknown>'?_0x424562['destcalleridname']:_0x424562[_0x76bd('0x18')]||_0x424562[_0x76bd('0x19')];_0x2756c8['phone']=_0x424562[_0x76bd('0x17')]&&_0x424562[_0x76bd('0x17')]!==_0x76bd('0x15')?_0x424562[_0x76bd('0x17')]:_0x424562[_0x76bd('0x18')]||_0x424562[_0x76bd('0x19')];}BPromise[_0x76bd('0x1a')]()['then'](cmContactRpc[_0x76bd('0x1b')]({'where':_[_0x76bd('0x1c')](_0x2756c8,['firstName'])}))[_0x76bd('0x1d')](function(_0x18d1fc){if(_0x18d1fc){_0x424562['xmd-contactid2']=_0x18d1fc['id'];emit(util[_0x76bd('0x1e')]('user:%s',_0xcaad2c['name']),util['format'](_0x76bd('0x1f'),_0x4c16cd[_0x76bd('0x20')][_0x76bd('0x21')]()),_[_0x76bd('0x22')](_0x424562,{'ListId':parseInt(_0x4c16cd[_0x76bd('0x11')],0xa)}));return;}else{return BPromise['resolve']()[_0x76bd('0x1d')](cmContactRpc[_0x76bd('0x23')](_0x2756c8));}})[_0x76bd('0x1d')](function(_0x442442){if(_0x442442){_0x424562[_0x76bd('0x24')]=_0x442442['id'];emit(util[_0x76bd('0x1e')]('user:%s',_0xcaad2c[_0x76bd('0x25')]),util[_0x76bd('0x1e')](_0x76bd('0x1f'),_0x4c16cd['action']['toLowerCase']()),_[_0x76bd('0x22')](_0x424562,{'ListId':parseInt(_0x4c16cd[_0x76bd('0x11')],0xa)}));}})['catch'](function(_0x312d8e){logger[_0x76bd('0x26')]('Error\x20creating\x20contact',JSON[_0x76bd('0xc')](_0x312d8e));});}else{if(_0xcaad2c){emit(util['format'](_0x76bd('0x27'),_0xcaad2c['name']),util['format'](_0x76bd('0x1f'),_0x4c16cd[_0x76bd('0x20')][_0x76bd('0x21')]()),_['merge']({'ListId':parseInt(_0x4c16cd['data1'],0xa)},_0x424562));}}};