0c3dbf178754032ed045b74633541ebc6e9071dc
[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 _0x7f71=['destcalleridname','destcalleridnum','phone','resolve','then','showContact','omit','firstName','xmd-contactid2','format','user:%s','name','trigger:%s','action','toLowerCase','merge','data1','createContact','catch','error','Error\x20creating\x20contact','bluebird','util','ioredis','../../../../config/environment','../../../../config/logger','../../rpc/cmContact','defaults','redis','socket.io-emitter','info','stringify','emit','exec','autoCreate','data2','routeId','<unknown>','calleridname','calleridnum','uniqueid'];(function(_0x2ae8ce,_0x2a5a1f){var _0x4bf686=function(_0x41cabf){while(--_0x41cabf){_0x2ae8ce['push'](_0x2ae8ce['shift']());}};_0x4bf686(++_0x2a5a1f);}(_0x7f71,0x10b));var _0x17f7=function(_0x35cc99,_0x5bb972){_0x35cc99=_0x35cc99-0x0;var _0x14373c=_0x7f71[_0x35cc99];return _0x14373c;};'use strict';var BPromise=require(_0x17f7('0x0'));var util=require(_0x17f7('0x1'));var _=require('lodash');var Redis=require(_0x17f7('0x2'));var config=require(_0x17f7('0x3'));var logger=require(_0x17f7('0x4'))('trigger');var cmContactRpc=require(_0x17f7('0x5'));config['redis']=_[_0x17f7('0x6')](config[_0x17f7('0x7')],{'host':'localhost','port':0x18eb});var io=require(_0x17f7('0x8'))(new Redis(config[_0x17f7('0x7')]));function emit(_0x179de6,_0x5fbff9,_0x498c39){logger[_0x17f7('0x9')](_0x179de6,_0x5fbff9,JSON[_0x17f7('0xa')](_0x498c39));io['to'](_0x179de6)[_0x17f7('0xb')](_0x5fbff9,_0x498c39);}exports[_0x17f7('0xc')]=function(_0x3d7a30,_0xc6ee5b,_0x3ba4a7){_0x3ba4a7[_0x17f7('0xd')]=0x0;if(_0xc6ee5b[_0x17f7('0xe')]&&parseInt(_0xc6ee5b[_0x17f7('0xe')],0xa)){var _0x399f93={'ListId':parseInt(_0xc6ee5b['data1'],0xa),'phone':_0x3ba4a7['calleridnum']};if(_['isNil'](_0x3ba4a7[_0x17f7('0xf')])){_0x399f93['firstName']=_0x3ba4a7['calleridname']&&_0x3ba4a7['calleridname']!==_0x17f7('0x10')?_0x3ba4a7[_0x17f7('0x11')]:_0x3ba4a7[_0x17f7('0x12')]||_0x3ba4a7[_0x17f7('0x13')];}else{_0x399f93['firstName']=_0x3ba4a7[_0x17f7('0x14')]&&_0x3ba4a7['destcalleridname']!==_0x17f7('0x10')?_0x3ba4a7[_0x17f7('0x14')]:_0x3ba4a7[_0x17f7('0x15')]||_0x3ba4a7[_0x17f7('0x13')];_0x399f93[_0x17f7('0x16')]=_0x3ba4a7[_0x17f7('0x14')]&&_0x3ba4a7[_0x17f7('0x14')]!=='<unknown>'?_0x3ba4a7[_0x17f7('0x14')]:_0x3ba4a7['destcalleridnum']||_0x3ba4a7['uniqueid'];}BPromise[_0x17f7('0x17')]()[_0x17f7('0x18')](cmContactRpc[_0x17f7('0x19')]({'where':_[_0x17f7('0x1a')](_0x399f93,[_0x17f7('0x1b')])}))[_0x17f7('0x18')](function(_0x36ce9c){if(_0x36ce9c){_0x3ba4a7[_0x17f7('0x1c')]=_0x36ce9c['id'];emit(util[_0x17f7('0x1d')](_0x17f7('0x1e'),_0x3d7a30[_0x17f7('0x1f')]),util[_0x17f7('0x1d')](_0x17f7('0x20'),_0xc6ee5b[_0x17f7('0x21')][_0x17f7('0x22')]()),_[_0x17f7('0x23')](_0x3ba4a7,{'ListId':parseInt(_0xc6ee5b[_0x17f7('0x24')],0xa)}));return;}else{return BPromise['resolve']()['then'](cmContactRpc[_0x17f7('0x25')](_0x399f93));}})[_0x17f7('0x18')](function(_0x326482){if(_0x326482){_0x3ba4a7[_0x17f7('0x1c')]=_0x326482['id'];emit(util['format'](_0x17f7('0x1e'),_0x3d7a30[_0x17f7('0x1f')]),util[_0x17f7('0x1d')](_0x17f7('0x20'),_0xc6ee5b[_0x17f7('0x21')][_0x17f7('0x22')]()),_[_0x17f7('0x23')](_0x3ba4a7,{'ListId':parseInt(_0xc6ee5b[_0x17f7('0x24')],0xa)}));}})[_0x17f7('0x26')](function(_0x10d972){logger[_0x17f7('0x27')](_0x17f7('0x28'),JSON[_0x17f7('0xa')](_0x10d972));});}else{if(_0x3d7a30){emit(util[_0x17f7('0x1d')](_0x17f7('0x1e'),_0x3d7a30[_0x17f7('0x1f')]),util[_0x17f7('0x1d')](_0x17f7('0x20'),_0xc6ee5b[_0x17f7('0x21')]['toLowerCase']()),_['merge']({'ListId':parseInt(_0xc6ee5b[_0x17f7('0x24')],0xa)},_0x3ba4a7));}}};