2d9b1d9675b03901260737245a7672b480897197
[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 _0x230f=['toLowerCase','merge','lodash','bluebird','ioredis','util','../../../../config/logger','trigger','defaults','redis','localhost','socket.io-emitter','info','[CM][%s][%s]','emit','data2','isNil','data5','xmd-contactid','ListId','data3','split','phone','$or','map','destcalleridnum','calleridnum','firstName','lastName','updatedAt','resolve','then','getContacts','length','[CM][%s][%s]\x20Contact\x20found:%s','uniqueid','[CM][%s][%s]\x20Multiple\x20contacts\x20found:[%s]','join','data4','routeId','calleridname','Unknown','destcalleridname','createContact','push','[CM][%s][%s]\x20Autocreate\x20disabled','<unknown>','format','user:%s','name','trigger:%s'];(function(_0x46d0c9,_0x526bfa){var _0x174506=function(_0x654bc6){while(--_0x654bc6){_0x46d0c9['push'](_0x46d0c9['shift']());}};_0x174506(++_0x526bfa);}(_0x230f,0x68));var _0xf230=function(_0x50439d,_0x3aed4c){_0x50439d=_0x50439d-0x0;var _0x5dc279=_0x230f[_0x50439d];return _0x5dc279;};'use strict';var _=require(_0xf230('0x0'));var BPromise=require(_0xf230('0x1'));var Redis=require(_0xf230('0x2'));var util=require(_0xf230('0x3'));var config=require('../../../../config/environment');var logger=require(_0xf230('0x4'))(_0xf230('0x5'));var cmContactRpc=require('../../rpc/cmContact');config['redis']=_[_0xf230('0x6')](config[_0xf230('0x7')],{'host':_0xf230('0x8'),'port':0x18eb});var io=require(_0xf230('0x9'))(new Redis(config[_0xf230('0x7')]));function emit(_0x188727,_0x3c5801,_0x1bcca4,_0x1ff7c4,_0x13c282){logger[_0xf230('0xa')](_0xf230('0xb'),_0x188727,_0x3c5801['id'],_0x1bcca4,_0x1ff7c4,JSON['stringify'](_0x13c282));io['to'](_0x1bcca4)[_0xf230('0xc')](_0x1ff7c4,_0x13c282);}exports['exec']=function(_0x4fea8c,_0x133505,_0x5c0a61,_0x469b9c){var _0x3a0481,_0x4aba0c;var _0xc6ff7d={};var _0x527de5;var _0x33963c=Number(_0x5c0a61['data1']);var _0x545918=_0x5c0a61[_0xf230('0xd')]?Boolean(Number(_0x5c0a61['data2'])):![];var _0x2f9811;var _0x125989=![];if(!_[_0xf230('0xe')](_0x5c0a61['data5'])){if(_0x5c0a61[_0xf230('0xf')]=='1')_0x125989=!![];}if(!_0x125989){if(_0x469b9c['xmd-contactid']){_0xc6ff7d['id']=_0x469b9c[_0xf230('0x10')];}}if(!_0xc6ff7d['id']){_0xc6ff7d[_0xf230('0x11')]=_0x33963c;_0x2f9811=_0x5c0a61[_0xf230('0x12')]&&_0x5c0a61[_0xf230('0x12')]!=='0'?_0x5c0a61[_0xf230('0x12')][_0xf230('0x13')](','):[_0xf230('0x14')];_0xc6ff7d[_0xf230('0x15')]=_[_0xf230('0x16')](_0x2f9811,function(_0x114d53){var _0x54d700={};_0x54d700[_0x114d53]=_0x469b9c['routeId']?_0x469b9c[_0xf230('0x17')]:_0x469b9c[_0xf230('0x18')];return _0x54d700;});_0x527de5=_0x469b9c['routeId']?_0x469b9c[_0xf230('0x17')]:_0x469b9c[_0xf230('0x18')];}var _0x3e21eb=['id',_0xf230('0x19'),_0xf230('0x1a'),_0xf230('0x14'),'mobile','fax',_0xf230('0x11'),'createdAt','scheduledAt',_0xf230('0x1b')];var _0x538325=_['union'](_0x3e21eb,_0x2f9811);BPromise[_0xf230('0x1c')]()[_0xf230('0x1d')](cmContactRpc[_0xf230('0x1e')]({'attributes':_0x538325,'where':_0xc6ff7d,'phone':_0x527de5}))[_0xf230('0x1d')](function(_0x15f5f6){_0x4aba0c=_0x15f5f6;if(!_['isEmpty'](_0x4aba0c)){if(_0x4aba0c[_0xf230('0x1f')]===0x1){_0x3a0481=_0x4aba0c[0x0];logger[_0xf230('0xa')](_0xf230('0x20'),_0x469b9c[_0xf230('0x21')],_0x133505['id'],_0x3a0481['id']);}else{logger[_0xf230('0xa')](_0xf230('0x22'),_0x469b9c[_0xf230('0x21')],_0x133505['id'],_[_0xf230('0x16')](_0x4aba0c,'id')[_0xf230('0x23')](','));}return;}else{logger[_0xf230('0xa')]('[CM][%s][%s]\x20Contact\x20not\x20found',_0x469b9c[_0xf230('0x21')],_0x133505['id']);var _0x494f4b={'ListId':_0x33963c};var _0x1f832c=_0x5c0a61['data4']&&_0x5c0a61[_0xf230('0x24')]!=='0'?_0x5c0a61['data4']:_0xf230('0x14');if(_0x545918){logger['info']('[CM][%s][%s]\x20Autocreate\x20enabled',_0x469b9c[_0xf230('0x21')],_0x133505['id']);_0x494f4b[_0x1f832c]=_[_0xf230('0xe')](_0x469b9c[_0xf230('0x25')])?_0x469b9c[_0xf230('0x18')]:_0x469b9c[_0xf230('0x17')];if(_[_0xf230('0xe')](_0x469b9c[_0xf230('0x25')])){_0x494f4b[_0xf230('0x19')]=_0x469b9c[_0xf230('0x26')]&&_0x469b9c[_0xf230('0x26')]!=='<unknown>'?_0x469b9c[_0xf230('0x26')]:_0xf230('0x27');}else{_0x494f4b[_0xf230('0x19')]=_0x469b9c[_0xf230('0x28')]&&_0x469b9c[_0xf230('0x28')]!=='<unknown>'?_0x469b9c[_0xf230('0x28')]:'Unknown';}return BPromise['resolve']()[_0xf230('0x1d')](cmContactRpc[_0xf230('0x29')](_0x494f4b))[_0xf230('0x1d')](function(_0x35ff05){_0x3a0481=_0x35ff05;_0x4aba0c[_0xf230('0x2a')](_0x35ff05);if(_0x3a0481){logger[_0xf230('0xa')]('[CM][%s][%s]\x20Contact\x20created:%s',_0x469b9c[_0xf230('0x21')],_0x133505['id'],_0x3a0481['id']);}return;});}else{logger[_0xf230('0xa')](_0xf230('0x2b'),_0x469b9c[_0xf230('0x21')],_0x133505['id']);_0x494f4b[_0x1f832c]=_[_0xf230('0xe')](_0x469b9c[_0xf230('0x25')])?_0x469b9c['calleridnum']:_0x469b9c[_0xf230('0x17')];if(_[_0xf230('0xe')](_0x469b9c[_0xf230('0x25')])){_0x494f4b[_0xf230('0x19')]=_0x469b9c[_0xf230('0x26')]&&_0x469b9c['calleridname']!==_0xf230('0x2c')?_0x469b9c[_0xf230('0x26')]:'Unknown';}else{_0x494f4b['firstName']=_0x469b9c[_0xf230('0x28')]&&_0x469b9c[_0xf230('0x28')]!==_0xf230('0x2c')?_0x469b9c[_0xf230('0x28')]:_0xf230('0x27');}_0x3a0481=_0x494f4b;_0x4aba0c[_0xf230('0x2a')](_0x494f4b);return;}}})[_0xf230('0x1d')](function(){if(_0x4fea8c){emit(_0x469b9c['uniqueid'],_0x133505,util[_0xf230('0x2d')](_0xf230('0x2e'),_0x4fea8c[_0xf230('0x2f')]),util[_0xf230('0x2d')](_0xf230('0x30'),_0x5c0a61['action'][_0xf230('0x31')]()),{'evt':_[_0xf230('0x32')](_0x469b9c,{'autoCreate':_0x545918}),'contact':_0x3a0481===undefined?{}:_0x3a0481,'contacts':_0x4aba0c[_0xf230('0x1f')]===0x0?undefined:_0x4aba0c});}});};