369897805e3d3beff594ade3e82a91591e5c676f
[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 _0x0f53=['redis','localhost','register','request','info','ChatMessage,\x20%s,\x20%s','request\x20sent','error','code','message','result','catch','ChatMessage','create','options','raw','CreateChatMessage','debug','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','jayson/promise','client','http'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x0f53,0x1d4));var _0x30f5=function(_0x2a2701,_0x51a875){_0x2a2701=_0x2a2701-0x0;var _0x4e47ea=_0x0f53[_0x2a2701];return _0x4e47ea;};'use strict';var _=require(_0x30f5('0x0'));var util=require(_0x30f5('0x1'));var moment=require(_0x30f5('0x2'));var BPromise=require(_0x30f5('0x3'));var rs=require(_0x30f5('0x4'));var fs=require('fs');var Redis=require(_0x30f5('0x5'));var db=require(_0x30f5('0x6'))['db'];var utils=require(_0x30f5('0x7'));var logger=require(_0x30f5('0x8'))('rpc');var config=require('../../config/environment');var jayson=require(_0x30f5('0x9'));var client=jayson[_0x30f5('0xa')][_0x30f5('0xb')]({'port':0x232a});config[_0x30f5('0xc')]=_['defaults'](config[_0x30f5('0xc')],{'host':_0x30f5('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x30f5('0xc')]));require('./chatMessage.socket')[_0x30f5('0xe')](socket);function respondWithRpcPromise(_0x4c90db,_0x2ce177,_0x11f590){return new BPromise(function(_0x36ddad,_0x29a2f8){return client[_0x30f5('0xf')](_0x4c90db,_0x11f590)['then'](function(_0x307906){logger[_0x30f5('0x10')](_0x30f5('0x11'),_0x2ce177,_0x30f5('0x12'));logger['debug']('ChatMessage,\x20%s,\x20%s,\x20%s',_0x2ce177,_0x30f5('0x12'),JSON['stringify'](_0x307906));if(_0x307906[_0x30f5('0x13')]){if(_0x307906['error'][_0x30f5('0x14')]===0x1f4){logger[_0x30f5('0x13')](_0x30f5('0x11'),_0x2ce177,_0x307906[_0x30f5('0x13')][_0x30f5('0x15')]);return _0x29a2f8(_0x307906[_0x30f5('0x13')]['message']);}logger[_0x30f5('0x13')](_0x30f5('0x11'),_0x2ce177,_0x307906[_0x30f5('0x13')]['message']);return _0x36ddad(_0x307906[_0x30f5('0x13')]['message']);}else{logger['info'](_0x30f5('0x11'),_0x2ce177,_0x30f5('0x12'));_0x36ddad(_0x307906[_0x30f5('0x16')][_0x30f5('0x15')]);}})[_0x30f5('0x17')](function(_0x3ae429){logger['error'](_0x30f5('0x11'),_0x2ce177,_0x3ae429);_0x29a2f8(_0x3ae429);});});}exports['CreateChatMessage']=function(_0x37f6e8){var _0x2b74b4=this;return new Promise(function(_0x603ddf,_0x138242){return db[_0x30f5('0x18')][_0x30f5('0x19')](_0x37f6e8['body'],{'raw':_0x37f6e8[_0x30f5('0x1a')]?_0x37f6e8[_0x30f5('0x1a')][_0x30f5('0x1b')]===undefined?!![]:![]:!![]})['then'](function(_0x2683dd){logger[_0x30f5('0x10')](_0x30f5('0x1c'),_0x37f6e8);logger[_0x30f5('0x1d')](_0x30f5('0x1c'),_0x37f6e8,JSON['stringify'](_0x2683dd));_0x603ddf(_0x2683dd);})['catch'](function(_0x3252ea){logger['error'](_0x30f5('0x1c'),_0x3252ea[_0x30f5('0x15')],_0x37f6e8);_0x138242(_0x2b74b4[_0x30f5('0x13')](0x1f4,_0x3252ea[_0x30f5('0x15')]));});});};