Built motion from commit 19a84241.|2.5.34
[motion2.git] / server / api / chatInteraction / chatInteraction.rpc.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 _0x99db=['bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','jayson/promise','client','redis','defaults','localhost','socket.io-emitter','./chatInteraction.socket','then','info','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatInteraction,\x20%s,\x20%s','message','result','catch','UpdateChatInteraction','ChatInteraction','update','body','options','raw','attributes','limit','AddTagsToChatInteraction','find','where','addTags','omit','ids','AddTags','lodash','util','moment'];(function(_0x57dcd4,_0x20f5b8){var _0x45f5d9=function(_0x346f82){while(--_0x346f82){_0x57dcd4['push'](_0x57dcd4['shift']());}};_0x45f5d9(++_0x20f5b8);}(_0x99db,0x7e));var _0xb99d=function(_0x381d3c,_0x4bc7d0){_0x381d3c=_0x381d3c-0x0;var _0x12542e=_0x99db[_0x381d3c];return _0x12542e;};'use strict';var _=require(_0xb99d('0x0'));var util=require(_0xb99d('0x1'));var moment=require(_0xb99d('0x2'));var BPromise=require(_0xb99d('0x3'));var rs=require(_0xb99d('0x4'));var fs=require('fs');var Redis=require(_0xb99d('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0xb99d('0x6'));var logger=require(_0xb99d('0x7'))(_0xb99d('0x8'));var config=require('../../config/environment');var jayson=require(_0xb99d('0x9'));var client=jayson[_0xb99d('0xa')]['http']({'port':0x232a});config[_0xb99d('0xb')]=_[_0xb99d('0xc')](config[_0xb99d('0xb')],{'host':_0xb99d('0xd'),'port':0x18eb});var socket=require(_0xb99d('0xe'))(new Redis(config['redis']));require(_0xb99d('0xf'))['register'](socket);function respondWithRpcPromise(_0x1b8bb1,_0x1f8616,_0x2ec015){return new BPromise(function(_0x5ec841,_0x5bd2cd){return client['request'](_0x1b8bb1,_0x2ec015)[_0xb99d('0x10')](function(_0x417854){logger[_0xb99d('0x11')]('ChatInteraction,\x20%s,\x20%s',_0x1f8616,_0xb99d('0x12'));logger[_0xb99d('0x13')](_0xb99d('0x14'),_0x1f8616,_0xb99d('0x12'),JSON[_0xb99d('0x15')](_0x417854));if(_0x417854[_0xb99d('0x16')]){if(_0x417854['error'][_0xb99d('0x17')]===0x1f4){logger['error'](_0xb99d('0x18'),_0x1f8616,_0x417854['error'][_0xb99d('0x19')]);return _0x5bd2cd(_0x417854[_0xb99d('0x16')][_0xb99d('0x19')]);}logger[_0xb99d('0x16')](_0xb99d('0x18'),_0x1f8616,_0x417854[_0xb99d('0x16')][_0xb99d('0x19')]);return _0x5ec841(_0x417854[_0xb99d('0x16')]['message']);}else{logger[_0xb99d('0x11')](_0xb99d('0x18'),_0x1f8616,_0xb99d('0x12'));_0x5ec841(_0x417854[_0xb99d('0x1a')][_0xb99d('0x19')]);}})[_0xb99d('0x1b')](function(_0x23a30d){logger[_0xb99d('0x16')](_0xb99d('0x18'),_0x1f8616,_0x23a30d);_0x5bd2cd(_0x23a30d);});});}exports[_0xb99d('0x1c')]=function(_0x21c800){var _0x44dee=this;return new Promise(function(_0x43e260,_0x1f0f71){return db[_0xb99d('0x1d')][_0xb99d('0x1e')](_0x21c800[_0xb99d('0x1f')],{'raw':_0x21c800[_0xb99d('0x20')]?_0x21c800['options'][_0xb99d('0x21')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x21c800[_0xb99d('0x20')]?_0x21c800[_0xb99d('0x20')]['where']||null:null,'attributes':_0x21c800[_0xb99d('0x20')]?_0x21c800[_0xb99d('0x20')][_0xb99d('0x22')]||null:null,'limit':_0x21c800[_0xb99d('0x20')]?_0x21c800[_0xb99d('0x20')][_0xb99d('0x23')]||null:null})[_0xb99d('0x10')](function(_0x5b7897){logger['info'](_0xb99d('0x1c'),_0x21c800);logger[_0xb99d('0x13')]('UpdateChatInteraction',_0x21c800,JSON['stringify'](_0x5b7897));_0x43e260(_0x5b7897);})[_0xb99d('0x1b')](function(_0x54d752){logger[_0xb99d('0x16')]('UpdateChatInteraction',_0x54d752[_0xb99d('0x19')],_0x21c800);_0x1f0f71(_0x44dee['error'](0x1f4,_0x54d752['message']));});});};exports[_0xb99d('0x24')]=function(_0x4a68a0){return new Promise(function(_0x46c9dd,_0x489c0d){return db['ChatInteraction'][_0xb99d('0x25')]({'where':_0x4a68a0[_0xb99d('0x20')]?_0x4a68a0[_0xb99d('0x20')][_0xb99d('0x26')]||null:null})[_0xb99d('0x10')](function(_0x44d4c3){if(_0x44d4c3){return _0x44d4c3[_0xb99d('0x27')](_0x4a68a0['body']['ids'],_[_0xb99d('0x28')](_0x4a68a0['body'],[_0xb99d('0x29'),'id'])||{});}})['spread'](function(_0x4b5e4b){logger[_0xb99d('0x11')](_0xb99d('0x2a'),_0x4a68a0);logger[_0xb99d('0x13')]('AddTags',_0x4a68a0,JSON['stringify'](_0x4b5e4b));_0x46c9dd(_0x4b5e4b);})['catch'](function(_0x53ad8d){logger['error'](_0xb99d('0x2a'),_0x53ad8d['message'],_0x4a68a0);_0x489c0d(_this[_0xb99d('0x16')](0x1f4,_0x53ad8d['message']));});});};