3b448af52bb94271f69461dcb18c5d2928ee5631
[motion2.git] / server / api / chatMessage / chatMessage.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 _0x0fcc=['../../config/environment','client','http','redis','localhost','socket.io-emitter','register','request','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','code','error','message','result','CreateChatMessage','ChatMessage','body','raw','catch','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc'];(function(_0x4ee792,_0x16c595){var _0x526542=function(_0x21b049){while(--_0x21b049){_0x4ee792['push'](_0x4ee792['shift']());}};_0x526542(++_0x16c595);}(_0x0fcc,0x8f));var _0xc0fc=function(_0x3de8a4,_0x289a5c){_0x3de8a4=_0x3de8a4-0x0;var _0x4635cf=_0x0fcc[_0x3de8a4];return _0x4635cf;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0xc0fc('0x0'));var BPromise=require('bluebird');var rs=require(_0xc0fc('0x1'));var fs=require('fs');var Redis=require(_0xc0fc('0x2'));var db=require(_0xc0fc('0x3'))['db'];var utils=require(_0xc0fc('0x4'));var logger=require(_0xc0fc('0x5'))(_0xc0fc('0x6'));var config=require(_0xc0fc('0x7'));var jayson=require('jayson/promise');var client=jayson[_0xc0fc('0x8')][_0xc0fc('0x9')]({'port':0x232a});config[_0xc0fc('0xa')]=_['defaults'](config['redis'],{'host':_0xc0fc('0xb'),'port':0x18eb});var socket=require(_0xc0fc('0xc'))(new Redis(config[_0xc0fc('0xa')]));require('./chatMessage.socket')[_0xc0fc('0xd')](socket);function respondWithRpcPromise(_0x47a41e,_0x53e74f,_0x415fcb){return new BPromise(function(_0x2b931f,_0x5057d6){return client[_0xc0fc('0xe')](_0x47a41e,_0x415fcb)['then'](function(_0x203b4b){logger[_0xc0fc('0xf')](_0xc0fc('0x10'),_0x53e74f,_0xc0fc('0x11'));logger[_0xc0fc('0x12')](_0xc0fc('0x13'),_0x53e74f,_0xc0fc('0x11'),JSON[_0xc0fc('0x14')](_0x203b4b));if(_0x203b4b['error']){if(_0x203b4b['error'][_0xc0fc('0x15')]===0x1f4){logger[_0xc0fc('0x16')](_0xc0fc('0x10'),_0x53e74f,_0x203b4b['error'][_0xc0fc('0x17')]);return _0x5057d6(_0x203b4b[_0xc0fc('0x16')][_0xc0fc('0x17')]);}logger['error'](_0xc0fc('0x10'),_0x53e74f,_0x203b4b[_0xc0fc('0x16')][_0xc0fc('0x17')]);return _0x2b931f(_0x203b4b[_0xc0fc('0x16')]['message']);}else{logger[_0xc0fc('0xf')](_0xc0fc('0x10'),_0x53e74f,_0xc0fc('0x11'));_0x2b931f(_0x203b4b[_0xc0fc('0x18')][_0xc0fc('0x17')]);}})['catch'](function(_0x5f1c9c){logger['error'](_0xc0fc('0x10'),_0x53e74f,_0x5f1c9c);_0x5057d6(_0x5f1c9c);});});}exports[_0xc0fc('0x19')]=function(_0x387651){var _0x57bf40=this;return new Promise(function(_0x36cac5,_0x57b46f){return db[_0xc0fc('0x1a')]['create'](_0x387651[_0xc0fc('0x1b')],{'raw':_0x387651['options']?_0x387651['options'][_0xc0fc('0x1c')]===undefined?!![]:![]:!![]})['then'](function(_0x35f1d7){logger['info'](_0xc0fc('0x19'),_0x387651);logger[_0xc0fc('0x12')](_0xc0fc('0x19'),_0x387651,JSON[_0xc0fc('0x14')](_0x35f1d7));_0x36cac5(_0x35f1d7);})[_0xc0fc('0x1d')](function(_0x4b3ce8){logger[_0xc0fc('0x16')](_0xc0fc('0x19'),_0x4b3ce8['message'],_0x387651);_0x57b46f(_0x57bf40[_0xc0fc('0x16')](0x1f4,_0x4b3ce8[_0xc0fc('0x17')]));});});};