Built motion from commit c738b9ac.|2.6.25
[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 _0x71be=['addTags','omit','AddTags','lodash','util','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','redis','localhost','socket.io-emitter','./chatInteraction.socket','register','request','then','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','update','body','options','raw','attributes','UpdateChatInteraction','AddTagsToChatInteraction','find','where'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x71be,0x17f));var _0xe71b=function(_0x1cfa0d,_0x4391f2){_0x1cfa0d=_0x1cfa0d-0x0;var _0xe33279=_0x71be[_0x1cfa0d];return _0xe33279;};'use strict';var _=require(_0xe71b('0x0'));var util=require(_0xe71b('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0xe71b('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xe71b('0x3'))['db'];var utils=require(_0xe71b('0x4'));var logger=require(_0xe71b('0x5'))(_0xe71b('0x6'));var config=require('../../config/environment');var jayson=require(_0xe71b('0x7'));var client=jayson[_0xe71b('0x8')]['http']({'port':0x232a});config[_0xe71b('0x9')]=_['defaults'](config[_0xe71b('0x9')],{'host':_0xe71b('0xa'),'port':0x18eb});var socket=require(_0xe71b('0xb'))(new Redis(config[_0xe71b('0x9')]));require(_0xe71b('0xc'))[_0xe71b('0xd')](socket);function respondWithRpcPromise(_0x2794ba,_0x142ef8,_0x57edda){return new BPromise(function(_0x46c000,_0x4a3be1){return client[_0xe71b('0xe')](_0x2794ba,_0x57edda)[_0xe71b('0xf')](function(_0x31858b){logger[_0xe71b('0x10')](_0xe71b('0x11'),_0x142ef8,_0xe71b('0x12'));logger[_0xe71b('0x13')](_0xe71b('0x14'),_0x142ef8,'request\x20sent',JSON[_0xe71b('0x15')](_0x31858b));if(_0x31858b['error']){if(_0x31858b[_0xe71b('0x16')][_0xe71b('0x17')]===0x1f4){logger[_0xe71b('0x16')]('ChatInteraction,\x20%s,\x20%s',_0x142ef8,_0x31858b['error']['message']);return _0x4a3be1(_0x31858b[_0xe71b('0x16')][_0xe71b('0x18')]);}logger[_0xe71b('0x16')]('ChatInteraction,\x20%s,\x20%s',_0x142ef8,_0x31858b[_0xe71b('0x16')]['message']);return _0x46c000(_0x31858b['error']['message']);}else{logger['info'](_0xe71b('0x11'),_0x142ef8,_0xe71b('0x12'));_0x46c000(_0x31858b['result'][_0xe71b('0x18')]);}})[_0xe71b('0x19')](function(_0x422a6c){logger[_0xe71b('0x16')](_0xe71b('0x11'),_0x142ef8,_0x422a6c);_0x4a3be1(_0x422a6c);});});}exports['UpdateChatInteraction']=function(_0x38a9ba){var _0x2da49d=this;return new Promise(function(_0x1a00f0,_0xcbde4b){return db['ChatInteraction'][_0xe71b('0x1a')](_0x38a9ba[_0xe71b('0x1b')],{'raw':_0x38a9ba[_0xe71b('0x1c')]?_0x38a9ba['options'][_0xe71b('0x1d')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x38a9ba['options']?_0x38a9ba[_0xe71b('0x1c')]['where']||null:null,'attributes':_0x38a9ba['options']?_0x38a9ba['options'][_0xe71b('0x1e')]||null:null,'limit':_0x38a9ba[_0xe71b('0x1c')]?_0x38a9ba['options']['limit']||null:null})['then'](function(_0x5c7fdd){logger[_0xe71b('0x10')](_0xe71b('0x1f'),_0x38a9ba);logger[_0xe71b('0x13')](_0xe71b('0x1f'),_0x38a9ba,JSON[_0xe71b('0x15')](_0x5c7fdd));_0x1a00f0(_0x5c7fdd);})[_0xe71b('0x19')](function(_0x5748eb){logger[_0xe71b('0x16')]('UpdateChatInteraction',_0x5748eb['message'],_0x38a9ba);_0xcbde4b(_0x2da49d[_0xe71b('0x16')](0x1f4,_0x5748eb['message']));});});};exports[_0xe71b('0x20')]=function(_0x11b37c){return new Promise(function(_0x560aaa,_0x481a53){return db['ChatInteraction'][_0xe71b('0x21')]({'where':_0x11b37c[_0xe71b('0x1c')]?_0x11b37c[_0xe71b('0x1c')][_0xe71b('0x22')]||null:null})['then'](function(_0xf40616){if(_0xf40616){return _0xf40616[_0xe71b('0x23')](_0x11b37c['body']['ids'],_[_0xe71b('0x24')](_0x11b37c[_0xe71b('0x1b')],['ids','id'])||{});}})['spread'](function(_0x348bf9){logger[_0xe71b('0x10')](_0xe71b('0x25'),_0x11b37c);logger[_0xe71b('0x13')](_0xe71b('0x25'),_0x11b37c,JSON[_0xe71b('0x15')](_0x348bf9));_0x560aaa(_0x348bf9);})[_0xe71b('0x19')](function(_0x300cef){logger[_0xe71b('0x16')](_0xe71b('0x25'),_0x300cef[_0xe71b('0x18')],_0x11b37c);_0x481a53(_this[_0xe71b('0x16')](0x1f4,_0x300cef[_0xe71b('0x18')]));});});};