aa08cb33f5e2d26a9d89e97009a7717c6b80f6fa
[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 _0x7fcf=['../../config/utils','../../config/logger','jayson/promise','client','http','defaults','redis','localhost','socket.io-emitter','./chatMessage.socket','register','request','then','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','catch','CreateChatMessage','ChatMessage','body','raw','lodash','util','bluebird','randomstring'];(function(_0x1ea301,_0x52a75e){var _0x36d758=function(_0x57eaed){while(--_0x57eaed){_0x1ea301['push'](_0x1ea301['shift']());}};_0x36d758(++_0x52a75e);}(_0x7fcf,0x128));var _0xf7fc=function(_0x4709c0,_0x3396c7){_0x4709c0=_0x4709c0-0x0;var _0x13348b=_0x7fcf[_0x4709c0];return _0x13348b;};'use strict';var _=require(_0xf7fc('0x0'));var util=require(_0xf7fc('0x1'));var moment=require('moment');var BPromise=require(_0xf7fc('0x2'));var rs=require(_0xf7fc('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0xf7fc('0x4'));var logger=require(_0xf7fc('0x5'))('rpc');var config=require('../../config/environment');var jayson=require(_0xf7fc('0x6'));var client=jayson[_0xf7fc('0x7')][_0xf7fc('0x8')]({'port':0x232a});config['redis']=_[_0xf7fc('0x9')](config[_0xf7fc('0xa')],{'host':_0xf7fc('0xb'),'port':0x18eb});var socket=require(_0xf7fc('0xc'))(new Redis(config['redis']));require(_0xf7fc('0xd'))[_0xf7fc('0xe')](socket);function respondWithRpcPromise(_0x3e20b9,_0x5c1f8f,_0xace7db){return new BPromise(function(_0x1d60ae,_0x1d75a3){return client[_0xf7fc('0xf')](_0x3e20b9,_0xace7db)[_0xf7fc('0x10')](function(_0x4db12e){logger['info'](_0xf7fc('0x11'),_0x5c1f8f,_0xf7fc('0x12'));logger[_0xf7fc('0x13')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x5c1f8f,_0xf7fc('0x12'),JSON[_0xf7fc('0x14')](_0x4db12e));if(_0x4db12e['error']){if(_0x4db12e[_0xf7fc('0x15')][_0xf7fc('0x16')]===0x1f4){logger[_0xf7fc('0x15')]('ChatMessage,\x20%s,\x20%s',_0x5c1f8f,_0x4db12e[_0xf7fc('0x15')][_0xf7fc('0x17')]);return _0x1d75a3(_0x4db12e[_0xf7fc('0x15')][_0xf7fc('0x17')]);}logger[_0xf7fc('0x15')](_0xf7fc('0x11'),_0x5c1f8f,_0x4db12e[_0xf7fc('0x15')][_0xf7fc('0x17')]);return _0x1d60ae(_0x4db12e['error'][_0xf7fc('0x17')]);}else{logger[_0xf7fc('0x18')](_0xf7fc('0x11'),_0x5c1f8f,_0xf7fc('0x12'));_0x1d60ae(_0x4db12e['result']['message']);}})[_0xf7fc('0x19')](function(_0x2226dc){logger[_0xf7fc('0x15')](_0xf7fc('0x11'),_0x5c1f8f,_0x2226dc);_0x1d75a3(_0x2226dc);});});}exports[_0xf7fc('0x1a')]=function(_0x493060){var _0x2634d1=this;return new Promise(function(_0x2ef355,_0x5052c0){return db[_0xf7fc('0x1b')]['create'](_0x493060[_0xf7fc('0x1c')],{'raw':_0x493060['options']?_0x493060['options'][_0xf7fc('0x1d')]===undefined?!![]:![]:!![]})['then'](function(_0x2926e2){logger[_0xf7fc('0x18')](_0xf7fc('0x1a'),_0x493060);logger[_0xf7fc('0x13')]('CreateChatMessage',_0x493060,JSON[_0xf7fc('0x14')](_0x2926e2));_0x2ef355(_0x2926e2);})['catch'](function(_0x43ede9){logger[_0xf7fc('0x15')](_0xf7fc('0x1a'),_0x43ede9[_0xf7fc('0x17')],_0x493060);_0x5052c0(_0x2634d1['error'](0x1f4,_0x43ede9['message']));});});};