Built motion from commit e1760111.|2.6.18
[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 _0x0bb1=['./chatInteraction.socket','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','ChatInteraction','update','options','raw','limit','then','UpdateChatInteraction','where','addTags','body','omit','ids','spread','AddTags','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','redis','defaults'];(function(_0x4efb56,_0x1ef9b0){var _0x4daf4e=function(_0x34681f){while(--_0x34681f){_0x4efb56['push'](_0x4efb56['shift']());}};_0x4daf4e(++_0x1ef9b0);}(_0x0bb1,0x162));var _0x10bb=function(_0x42a44a,_0x15ca12){_0x42a44a=_0x42a44a-0x0;var _0x1e6ab6=_0x0bb1[_0x42a44a];return _0x1e6ab6;};'use strict';var _=require(_0x10bb('0x0'));var util=require(_0x10bb('0x1'));var moment=require(_0x10bb('0x2'));var BPromise=require(_0x10bb('0x3'));var rs=require(_0x10bb('0x4'));var fs=require('fs');var Redis=require(_0x10bb('0x5'));var db=require(_0x10bb('0x6'))['db'];var utils=require(_0x10bb('0x7'));var logger=require(_0x10bb('0x8'))(_0x10bb('0x9'));var config=require('../../config/environment');var jayson=require(_0x10bb('0xa'));var client=jayson[_0x10bb('0xb')][_0x10bb('0xc')]({'port':0x232a});config[_0x10bb('0xd')]=_[_0x10bb('0xe')](config[_0x10bb('0xd')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x10bb('0xd')]));require(_0x10bb('0xf'))['register'](socket);function respondWithRpcPromise(_0x23ec2e,_0x254b43,_0x4549ce){return new BPromise(function(_0x1bd4b0,_0x24b084){return client['request'](_0x23ec2e,_0x4549ce)['then'](function(_0x532ceb){logger[_0x10bb('0x10')](_0x10bb('0x11'),_0x254b43,_0x10bb('0x12'));logger[_0x10bb('0x13')](_0x10bb('0x14'),_0x254b43,_0x10bb('0x12'),JSON[_0x10bb('0x15')](_0x532ceb));if(_0x532ceb[_0x10bb('0x16')]){if(_0x532ceb[_0x10bb('0x16')][_0x10bb('0x17')]===0x1f4){logger[_0x10bb('0x16')](_0x10bb('0x11'),_0x254b43,_0x532ceb[_0x10bb('0x16')][_0x10bb('0x18')]);return _0x24b084(_0x532ceb[_0x10bb('0x16')][_0x10bb('0x18')]);}logger[_0x10bb('0x16')](_0x10bb('0x11'),_0x254b43,_0x532ceb[_0x10bb('0x16')][_0x10bb('0x18')]);return _0x1bd4b0(_0x532ceb['error'][_0x10bb('0x18')]);}else{logger['info'](_0x10bb('0x11'),_0x254b43,_0x10bb('0x12'));_0x1bd4b0(_0x532ceb[_0x10bb('0x19')][_0x10bb('0x18')]);}})[_0x10bb('0x1a')](function(_0x1fbe39){logger['error'](_0x10bb('0x11'),_0x254b43,_0x1fbe39);_0x24b084(_0x1fbe39);});});}exports['UpdateChatInteraction']=function(_0x3e1897){var _0x5bf8fd=this;return new Promise(function(_0x574c19,_0x120ac8){return db[_0x10bb('0x1b')][_0x10bb('0x1c')](_0x3e1897['body'],{'raw':_0x3e1897['options']?_0x3e1897[_0x10bb('0x1d')][_0x10bb('0x1e')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x3e1897[_0x10bb('0x1d')]?_0x3e1897[_0x10bb('0x1d')]['where']||null:null,'attributes':_0x3e1897[_0x10bb('0x1d')]?_0x3e1897['options']['attributes']||null:null,'limit':_0x3e1897[_0x10bb('0x1d')]?_0x3e1897['options'][_0x10bb('0x1f')]||null:null})[_0x10bb('0x20')](function(_0x3f70cd){logger[_0x10bb('0x10')](_0x10bb('0x21'),_0x3e1897);logger['debug'](_0x10bb('0x21'),_0x3e1897,JSON[_0x10bb('0x15')](_0x3f70cd));_0x574c19(_0x3f70cd);})[_0x10bb('0x1a')](function(_0x43b902){logger['error'](_0x10bb('0x21'),_0x43b902[_0x10bb('0x18')],_0x3e1897);_0x120ac8(_0x5bf8fd[_0x10bb('0x16')](0x1f4,_0x43b902[_0x10bb('0x18')]));});});};exports['AddTagsToChatInteraction']=function(_0x14416d){return new Promise(function(_0x266d43,_0x1cd2fb){return db['ChatInteraction']['find']({'where':_0x14416d[_0x10bb('0x1d')]?_0x14416d[_0x10bb('0x1d')][_0x10bb('0x22')]||null:null})[_0x10bb('0x20')](function(_0x1fa1be){if(_0x1fa1be){return _0x1fa1be[_0x10bb('0x23')](_0x14416d[_0x10bb('0x24')]['ids'],_[_0x10bb('0x25')](_0x14416d['body'],[_0x10bb('0x26'),'id'])||{});}})[_0x10bb('0x27')](function(_0x13417a){logger[_0x10bb('0x10')]('AddTags',_0x14416d);logger[_0x10bb('0x13')](_0x10bb('0x28'),_0x14416d,JSON['stringify'](_0x13417a));_0x266d43(_0x13417a);})[_0x10bb('0x1a')](function(_0xafe296){logger[_0x10bb('0x16')](_0x10bb('0x28'),_0xafe296[_0x10bb('0x18')],_0x14416d);_0x1cd2fb(_this[_0x10bb('0x16')](0x1f4,_0xafe296['message']));});});};