Built motion from commit (unavailable).|2.4.21
[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 _0xf368=['http','redis','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','CreateChatMessage','create','options','raw','lodash','util','moment','bluebird','randomstring','../../mysqldb','../../config/environment','client'];(function(_0x56b389,_0x56a28f){var _0x7cc435=function(_0x3ad2ce){while(--_0x3ad2ce){_0x56b389['push'](_0x56b389['shift']());}};_0x7cc435(++_0x56a28f);}(_0xf368,0x124));var _0x8f36=function(_0x4d01ae,_0xf7b032){_0x4d01ae=_0x4d01ae-0x0;var _0x343d02=_0xf368[_0x4d01ae];return _0x343d02;};'use strict';var _=require(_0x8f36('0x0'));var util=require(_0x8f36('0x1'));var moment=require(_0x8f36('0x2'));var BPromise=require(_0x8f36('0x3'));var rs=require(_0x8f36('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x8f36('0x5'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')('rpc');var config=require(_0x8f36('0x6'));var jayson=require('jayson/promise');var client=jayson[_0x8f36('0x7')][_0x8f36('0x8')]({'port':0x232a});config[_0x8f36('0x9')]=_[_0x8f36('0xa')](config[_0x8f36('0x9')],{'host':_0x8f36('0xb'),'port':0x18eb});var socket=require(_0x8f36('0xc'))(new Redis(config[_0x8f36('0x9')]));require(_0x8f36('0xd'))[_0x8f36('0xe')](socket);function respondWithRpcPromise(_0x1985f4,_0x4ccd65,_0x1e47f2){return new BPromise(function(_0x1116a2,_0x349696){return client['request'](_0x1985f4,_0x1e47f2)[_0x8f36('0xf')](function(_0xb4a88f){logger[_0x8f36('0x10')](_0x8f36('0x11'),_0x4ccd65,_0x8f36('0x12'));logger[_0x8f36('0x13')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x4ccd65,_0x8f36('0x12'),JSON[_0x8f36('0x14')](_0xb4a88f));if(_0xb4a88f[_0x8f36('0x15')]){if(_0xb4a88f[_0x8f36('0x15')][_0x8f36('0x16')]===0x1f4){logger[_0x8f36('0x15')]('ChatMessage,\x20%s,\x20%s',_0x4ccd65,_0xb4a88f[_0x8f36('0x15')][_0x8f36('0x17')]);return _0x349696(_0xb4a88f['error']['message']);}logger['error']('ChatMessage,\x20%s,\x20%s',_0x4ccd65,_0xb4a88f[_0x8f36('0x15')][_0x8f36('0x17')]);return _0x1116a2(_0xb4a88f['error'][_0x8f36('0x17')]);}else{logger[_0x8f36('0x10')](_0x8f36('0x11'),_0x4ccd65,_0x8f36('0x12'));_0x1116a2(_0xb4a88f[_0x8f36('0x18')][_0x8f36('0x17')]);}})[_0x8f36('0x19')](function(_0x38b3e5){logger[_0x8f36('0x15')](_0x8f36('0x11'),_0x4ccd65,_0x38b3e5);_0x349696(_0x38b3e5);});});}exports[_0x8f36('0x1a')]=function(_0x52a98e){var _0x574316=this;return new Promise(function(_0x42a5bc,_0xc1c2d7){return db['ChatMessage'][_0x8f36('0x1b')](_0x52a98e['body'],{'raw':_0x52a98e['options']?_0x52a98e[_0x8f36('0x1c')][_0x8f36('0x1d')]===undefined?!![]:![]:!![]})['then'](function(_0x460475){logger['info'](_0x8f36('0x1a'),_0x52a98e);logger[_0x8f36('0x13')](_0x8f36('0x1a'),_0x52a98e,JSON[_0x8f36('0x14')](_0x460475));_0x42a5bc(_0x460475);})[_0x8f36('0x19')](function(_0x57abda){logger[_0x8f36('0x15')](_0x8f36('0x1a'),_0x57abda['message'],_0x52a98e);_0xc1c2d7(_0x574316[_0x8f36('0x15')](0x1f4,_0x57abda[_0x8f36('0x17')]));});});};