Built motion from commit 746c7d2a.|2.5.35
[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 _0xedc4=['register','request','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','ChatInteraction','update','body','options','raw','where','attributes','limit','then','UpdateChatInteraction','find','addTags','ids','AddTags','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','http','redis','localhost','socket.io-emitter','./chatInteraction.socket'];(function(_0x17eb11,_0x25d8c6){var _0x559093=function(_0x1bf619){while(--_0x1bf619){_0x17eb11['push'](_0x17eb11['shift']());}};_0x559093(++_0x25d8c6);}(_0xedc4,0x166));var _0x4edc=function(_0x17d9e3,_0x1f969c){_0x17d9e3=_0x17d9e3-0x0;var _0x14192d=_0xedc4[_0x17d9e3];return _0x14192d;};'use strict';var _=require('lodash');var util=require(_0x4edc('0x0'));var moment=require('moment');var BPromise=require(_0x4edc('0x1'));var rs=require(_0x4edc('0x2'));var fs=require('fs');var Redis=require(_0x4edc('0x3'));var db=require(_0x4edc('0x4'))['db'];var utils=require(_0x4edc('0x5'));var logger=require(_0x4edc('0x6'))('rpc');var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson['client'][_0x4edc('0x7')]({'port':0x232a});config[_0x4edc('0x8')]=_['defaults'](config['redis'],{'host':_0x4edc('0x9'),'port':0x18eb});var socket=require(_0x4edc('0xa'))(new Redis(config[_0x4edc('0x8')]));require(_0x4edc('0xb'))[_0x4edc('0xc')](socket);function respondWithRpcPromise(_0x1043e3,_0x58a413,_0x34f23d){return new BPromise(function(_0x37378a,_0x15f9c3){return client[_0x4edc('0xd')](_0x1043e3,_0x34f23d)['then'](function(_0x250b4b){logger[_0x4edc('0xe')](_0x4edc('0xf'),_0x58a413,_0x4edc('0x10'));logger[_0x4edc('0x11')](_0x4edc('0x12'),_0x58a413,_0x4edc('0x10'),JSON[_0x4edc('0x13')](_0x250b4b));if(_0x250b4b[_0x4edc('0x14')]){if(_0x250b4b['error']['code']===0x1f4){logger['error']('ChatInteraction,\x20%s,\x20%s',_0x58a413,_0x250b4b[_0x4edc('0x14')]['message']);return _0x15f9c3(_0x250b4b[_0x4edc('0x14')][_0x4edc('0x15')]);}logger[_0x4edc('0x14')](_0x4edc('0xf'),_0x58a413,_0x250b4b[_0x4edc('0x14')][_0x4edc('0x15')]);return _0x37378a(_0x250b4b[_0x4edc('0x14')][_0x4edc('0x15')]);}else{logger[_0x4edc('0xe')]('ChatInteraction,\x20%s,\x20%s',_0x58a413,_0x4edc('0x10'));_0x37378a(_0x250b4b['result'][_0x4edc('0x15')]);}})[_0x4edc('0x16')](function(_0x5368b0){logger[_0x4edc('0x14')](_0x4edc('0xf'),_0x58a413,_0x5368b0);_0x15f9c3(_0x5368b0);});});}exports['UpdateChatInteraction']=function(_0x4460e3){var _0x49c652=this;return new Promise(function(_0x6ef155,_0xaa6412){return db[_0x4edc('0x17')][_0x4edc('0x18')](_0x4460e3[_0x4edc('0x19')],{'raw':_0x4460e3[_0x4edc('0x1a')]?_0x4460e3[_0x4edc('0x1a')][_0x4edc('0x1b')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x4460e3[_0x4edc('0x1a')]?_0x4460e3[_0x4edc('0x1a')][_0x4edc('0x1c')]||null:null,'attributes':_0x4460e3[_0x4edc('0x1a')]?_0x4460e3[_0x4edc('0x1a')][_0x4edc('0x1d')]||null:null,'limit':_0x4460e3[_0x4edc('0x1a')]?_0x4460e3['options'][_0x4edc('0x1e')]||null:null})[_0x4edc('0x1f')](function(_0x447622){logger[_0x4edc('0xe')](_0x4edc('0x20'),_0x4460e3);logger['debug'](_0x4edc('0x20'),_0x4460e3,JSON[_0x4edc('0x13')](_0x447622));_0x6ef155(_0x447622);})[_0x4edc('0x16')](function(_0x37f27f){logger['error']('UpdateChatInteraction',_0x37f27f['message'],_0x4460e3);_0xaa6412(_0x49c652[_0x4edc('0x14')](0x1f4,_0x37f27f[_0x4edc('0x15')]));});});};exports['AddTagsToChatInteraction']=function(_0x147358){return new Promise(function(_0x514c4b,_0x47b1e1){return db[_0x4edc('0x17')][_0x4edc('0x21')]({'where':_0x147358[_0x4edc('0x1a')]?_0x147358[_0x4edc('0x1a')][_0x4edc('0x1c')]||null:null})[_0x4edc('0x1f')](function(_0x5bd8c0){if(_0x5bd8c0){return _0x5bd8c0[_0x4edc('0x22')](_0x147358[_0x4edc('0x19')][_0x4edc('0x23')],_['omit'](_0x147358['body'],['ids','id'])||{});}})['spread'](function(_0x6086e4){logger['info']('AddTags',_0x147358);logger[_0x4edc('0x11')](_0x4edc('0x24'),_0x147358,JSON['stringify'](_0x6086e4));_0x514c4b(_0x6086e4);})[_0x4edc('0x16')](function(_0x4b649){logger[_0x4edc('0x14')](_0x4edc('0x24'),_0x4b649[_0x4edc('0x15')],_0x147358);_0x47b1e1(_this[_0x4edc('0x14')](0x1f4,_0x4b649[_0x4edc('0x15')]));});});};