d2593ede956c430bbfff80a5a1a4cf0d65668f86
[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 _0xb609=['rpc','../../config/environment','jayson/promise','http','redis','defaults','socket.io-emitter','./chatMessage.socket','register','request','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','create','body','options','raw','CreateChatMessage','lodash','util','moment','bluebird'];(function(_0x23983a,_0x38947d){var _0x127ff1=function(_0x374003){while(--_0x374003){_0x23983a['push'](_0x23983a['shift']());}};_0x127ff1(++_0x38947d);}(_0xb609,0xb6));var _0x9b60=function(_0x32a606,_0x28be38){_0x32a606=_0x32a606-0x0;var _0x68ea68=_0xb609[_0x32a606];return _0x68ea68;};'use strict';var _=require(_0x9b60('0x0'));var util=require(_0x9b60('0x1'));var moment=require(_0x9b60('0x2'));var BPromise=require(_0x9b60('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x9b60('0x4'));var config=require(_0x9b60('0x5'));var jayson=require(_0x9b60('0x6'));var client=jayson['client'][_0x9b60('0x7')]({'port':0x232a});config[_0x9b60('0x8')]=_[_0x9b60('0x9')](config[_0x9b60('0x8')],{'host':'localhost','port':0x18eb});var socket=require(_0x9b60('0xa'))(new Redis(config[_0x9b60('0x8')]));require(_0x9b60('0xb'))[_0x9b60('0xc')](socket);function respondWithRpcPromise(_0x101a45,_0x436529,_0xccbd54){return new BPromise(function(_0x2163a2,_0x1caf48){return client[_0x9b60('0xd')](_0x101a45,_0xccbd54)[_0x9b60('0xe')](function(_0x435ea7){logger[_0x9b60('0xf')](_0x9b60('0x10'),_0x436529,_0x9b60('0x11'));logger[_0x9b60('0x12')](_0x9b60('0x13'),_0x436529,_0x9b60('0x11'),JSON[_0x9b60('0x14')](_0x435ea7));if(_0x435ea7[_0x9b60('0x15')]){if(_0x435ea7['error'][_0x9b60('0x16')]===0x1f4){logger['error'](_0x9b60('0x10'),_0x436529,_0x435ea7[_0x9b60('0x15')][_0x9b60('0x17')]);return _0x1caf48(_0x435ea7[_0x9b60('0x15')]['message']);}logger['error'](_0x9b60('0x10'),_0x436529,_0x435ea7[_0x9b60('0x15')][_0x9b60('0x17')]);return _0x2163a2(_0x435ea7[_0x9b60('0x15')][_0x9b60('0x17')]);}else{logger[_0x9b60('0xf')](_0x9b60('0x10'),_0x436529,_0x9b60('0x11'));_0x2163a2(_0x435ea7[_0x9b60('0x18')]['message']);}})[_0x9b60('0x19')](function(_0x36e2d2){logger[_0x9b60('0x15')](_0x9b60('0x10'),_0x436529,_0x36e2d2);_0x1caf48(_0x36e2d2);});});}exports['CreateChatMessage']=function(_0x1f103c){var _0x68e0dd=this;return new Promise(function(_0x140dc8,_0x31622d){return db['ChatMessage'][_0x9b60('0x1a')](_0x1f103c[_0x9b60('0x1b')],{'raw':_0x1f103c['options']?_0x1f103c[_0x9b60('0x1c')][_0x9b60('0x1d')]===undefined?!![]:![]:!![]})[_0x9b60('0xe')](function(_0x3eebfe){logger[_0x9b60('0xf')](_0x9b60('0x1e'),_0x1f103c);logger[_0x9b60('0x12')](_0x9b60('0x1e'),_0x1f103c,JSON[_0x9b60('0x14')](_0x3eebfe));_0x140dc8(_0x3eebfe);})[_0x9b60('0x19')](function(_0x5df559){logger['error'](_0x9b60('0x1e'),_0x5df559[_0x9b60('0x17')],_0x1f103c);_0x31622d(_0x68e0dd[_0x9b60('0x15')](0x1f4,_0x5df559[_0x9b60('0x17')]));});});};