912f412525565351c91a9bee2e6634a99f4dbfb7
[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 _0x529a=['moment','ioredis','../../mysqldb','rpc','../../config/environment','jayson/promise','redis','defaults','localhost','./chatMessage.socket','register','request','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','CreateChatMessage','create','body','options','raw','debug','catch','lodash'];(function(_0x135483,_0x581153){var _0x22ebe4=function(_0x36ef27){while(--_0x36ef27){_0x135483['push'](_0x135483['shift']());}};_0x22ebe4(++_0x581153);}(_0x529a,0x77));var _0xa529=function(_0x25662e,_0x4cec68){_0x25662e=_0x25662e-0x0;var _0x59b7bc=_0x529a[_0x25662e];return _0x59b7bc;};'use strict';var _=require(_0xa529('0x0'));var util=require('util');var moment=require(_0xa529('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xa529('0x2'));var db=require(_0xa529('0x3'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0xa529('0x4'));var config=require(_0xa529('0x5'));var jayson=require(_0xa529('0x6'));var client=jayson['client']['http']({'port':0x232a});config[_0xa529('0x7')]=_[_0xa529('0x8')](config[_0xa529('0x7')],{'host':_0xa529('0x9'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xa529('0x7')]));require(_0xa529('0xa'))[_0xa529('0xb')](socket);function respondWithRpcPromise(_0x5e6dbe,_0x32e4e7,_0x2eb401){return new BPromise(function(_0x860252,_0x283589){return client[_0xa529('0xc')](_0x5e6dbe,_0x2eb401)[_0xa529('0xd')](function(_0x1e4011){logger[_0xa529('0xe')](_0xa529('0xf'),_0x32e4e7,_0xa529('0x10'));logger['debug'](_0xa529('0x11'),_0x32e4e7,_0xa529('0x10'),JSON[_0xa529('0x12')](_0x1e4011));if(_0x1e4011[_0xa529('0x13')]){if(_0x1e4011['error'][_0xa529('0x14')]===0x1f4){logger['error']('ChatMessage,\x20%s,\x20%s',_0x32e4e7,_0x1e4011[_0xa529('0x13')][_0xa529('0x15')]);return _0x283589(_0x1e4011['error'][_0xa529('0x15')]);}logger[_0xa529('0x13')]('ChatMessage,\x20%s,\x20%s',_0x32e4e7,_0x1e4011['error']['message']);return _0x860252(_0x1e4011[_0xa529('0x13')]['message']);}else{logger[_0xa529('0xe')](_0xa529('0xf'),_0x32e4e7,_0xa529('0x10'));_0x860252(_0x1e4011[_0xa529('0x16')][_0xa529('0x15')]);}})['catch'](function(_0x2dff3b){logger[_0xa529('0x13')](_0xa529('0xf'),_0x32e4e7,_0x2dff3b);_0x283589(_0x2dff3b);});});}exports[_0xa529('0x17')]=function(_0x496c20){var _0x118a99=this;return new Promise(function(_0x2f383e,_0x1580d4){return db['ChatMessage'][_0xa529('0x18')](_0x496c20[_0xa529('0x19')],{'raw':_0x496c20[_0xa529('0x1a')]?_0x496c20[_0xa529('0x1a')][_0xa529('0x1b')]===undefined?!![]:![]:!![]})['then'](function(_0x5c6ecc){logger['info'](_0xa529('0x17'),_0x496c20);logger[_0xa529('0x1c')](_0xa529('0x17'),_0x496c20,JSON[_0xa529('0x12')](_0x5c6ecc));_0x2f383e(_0x5c6ecc);})[_0xa529('0x1d')](function(_0x5a2b15){logger[_0xa529('0x13')](_0xa529('0x17'),_0x5a2b15[_0xa529('0x15')],_0x496c20);_0x1580d4(_0x118a99[_0xa529('0x13')](0x1f4,_0x5a2b15[_0xa529('0x15')]));});});};