b5eb30d0afd0aaee38dfb3e0329e33590779a63f
[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 _0x1f42=['../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','redis','localhost','socket.io-emitter','./chatMessage.socket','register','request','then','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','error','message','info','result','catch','ChatMessage','create','body','options','raw','CreateChatMessage','stringify','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb'];(function(_0x5304cf,_0x1848d4){var _0x1afa02=function(_0x51614e){while(--_0x51614e){_0x5304cf['push'](_0x5304cf['shift']());}};_0x1afa02(++_0x1848d4);}(_0x1f42,0xf5));var _0x21f4=function(_0x3fccf9,_0x456817){_0x3fccf9=_0x3fccf9-0x0;var _0x231b9c=_0x1f42[_0x3fccf9];return _0x231b9c;};'use strict';var _=require(_0x21f4('0x0'));var util=require(_0x21f4('0x1'));var moment=require(_0x21f4('0x2'));var BPromise=require(_0x21f4('0x3'));var rs=require(_0x21f4('0x4'));var fs=require('fs');var Redis=require(_0x21f4('0x5'));var db=require(_0x21f4('0x6'))['db'];var utils=require(_0x21f4('0x7'));var logger=require(_0x21f4('0x8'))('rpc');var config=require(_0x21f4('0x9'));var jayson=require(_0x21f4('0xa'));var client=jayson[_0x21f4('0xb')][_0x21f4('0xc')]({'port':0x232a});config['redis']=_['defaults'](config[_0x21f4('0xd')],{'host':_0x21f4('0xe'),'port':0x18eb});var socket=require(_0x21f4('0xf'))(new Redis(config['redis']));require(_0x21f4('0x10'))[_0x21f4('0x11')](socket);function respondWithRpcPromise(_0x8e65e,_0x24e1b4,_0xd0502f){return new BPromise(function(_0x5014f9,_0xf6adbe){return client[_0x21f4('0x12')](_0x8e65e,_0xd0502f)[_0x21f4('0x13')](function(_0x3f1472){logger['info'](_0x21f4('0x14'),_0x24e1b4,_0x21f4('0x15'));logger[_0x21f4('0x16')](_0x21f4('0x17'),_0x24e1b4,_0x21f4('0x15'),JSON['stringify'](_0x3f1472));if(_0x3f1472[_0x21f4('0x18')]){if(_0x3f1472[_0x21f4('0x18')]['code']===0x1f4){logger[_0x21f4('0x18')]('ChatMessage,\x20%s,\x20%s',_0x24e1b4,_0x3f1472['error']['message']);return _0xf6adbe(_0x3f1472[_0x21f4('0x18')]['message']);}logger[_0x21f4('0x18')](_0x21f4('0x14'),_0x24e1b4,_0x3f1472[_0x21f4('0x18')][_0x21f4('0x19')]);return _0x5014f9(_0x3f1472['error'][_0x21f4('0x19')]);}else{logger[_0x21f4('0x1a')](_0x21f4('0x14'),_0x24e1b4,_0x21f4('0x15'));_0x5014f9(_0x3f1472[_0x21f4('0x1b')][_0x21f4('0x19')]);}})[_0x21f4('0x1c')](function(_0x3e7dfb){logger[_0x21f4('0x18')](_0x21f4('0x14'),_0x24e1b4,_0x3e7dfb);_0xf6adbe(_0x3e7dfb);});});}exports['CreateChatMessage']=function(_0x5d092e){var _0x1ceed1=this;return new Promise(function(_0x4adf2f,_0x50ab39){return db[_0x21f4('0x1d')][_0x21f4('0x1e')](_0x5d092e[_0x21f4('0x1f')],{'raw':_0x5d092e[_0x21f4('0x20')]?_0x5d092e[_0x21f4('0x20')][_0x21f4('0x21')]===undefined?!![]:![]:!![]})[_0x21f4('0x13')](function(_0x248502){logger[_0x21f4('0x1a')]('CreateChatMessage',_0x5d092e);logger['debug'](_0x21f4('0x22'),_0x5d092e,JSON[_0x21f4('0x23')](_0x248502));_0x4adf2f(_0x248502);})[_0x21f4('0x1c')](function(_0x3f1be8){logger['error'](_0x21f4('0x22'),_0x3f1be8[_0x21f4('0x19')],_0x5d092e);_0x50ab39(_0x1ceed1[_0x21f4('0x18')](0x1f4,_0x3f1be8[_0x21f4('0x19')]));});});};