Built motion from commit 25580385.|2.6.2
[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 _0x5c89=['message','result','catch','CreateChatMessage','ChatMessage','body','options','raw','lodash','util','moment','../../config/utils','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./chatMessage.socket','request','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','error'];(function(_0x42cae2,_0x284ef8){var _0x5f256f=function(_0x41abc8){while(--_0x41abc8){_0x42cae2['push'](_0x42cae2['shift']());}};_0x5f256f(++_0x284ef8);}(_0x5c89,0x182));var _0x95c8=function(_0x3c6562,_0x3ba51f){_0x3c6562=_0x3c6562-0x0;var _0x1f4ee9=_0x5c89[_0x3c6562];return _0x1f4ee9;};'use strict';var _=require(_0x95c8('0x0'));var util=require(_0x95c8('0x1'));var moment=require(_0x95c8('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x95c8('0x3'));var logger=require('../../config/logger')(_0x95c8('0x4'));var config=require(_0x95c8('0x5'));var jayson=require(_0x95c8('0x6'));var client=jayson[_0x95c8('0x7')][_0x95c8('0x8')]({'port':0x232a});config[_0x95c8('0x9')]=_[_0x95c8('0xa')](config[_0x95c8('0x9')],{'host':_0x95c8('0xb'),'port':0x18eb});var socket=require(_0x95c8('0xc'))(new Redis(config['redis']));require(_0x95c8('0xd'))['register'](socket);function respondWithRpcPromise(_0xc2f873,_0x3db4c3,_0x118fbd){return new BPromise(function(_0x297ba7,_0x461743){return client[_0x95c8('0xe')](_0xc2f873,_0x118fbd)['then'](function(_0x207e6c){logger['info'](_0x95c8('0xf'),_0x3db4c3,_0x95c8('0x10'));logger[_0x95c8('0x11')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x3db4c3,_0x95c8('0x10'),JSON['stringify'](_0x207e6c));if(_0x207e6c['error']){if(_0x207e6c['error']['code']===0x1f4){logger[_0x95c8('0x12')]('ChatMessage,\x20%s,\x20%s',_0x3db4c3,_0x207e6c['error']['message']);return _0x461743(_0x207e6c[_0x95c8('0x12')][_0x95c8('0x13')]);}logger['error'](_0x95c8('0xf'),_0x3db4c3,_0x207e6c[_0x95c8('0x12')][_0x95c8('0x13')]);return _0x297ba7(_0x207e6c['error'][_0x95c8('0x13')]);}else{logger['info'](_0x95c8('0xf'),_0x3db4c3,_0x95c8('0x10'));_0x297ba7(_0x207e6c[_0x95c8('0x14')][_0x95c8('0x13')]);}})[_0x95c8('0x15')](function(_0x1dc42e){logger[_0x95c8('0x12')](_0x95c8('0xf'),_0x3db4c3,_0x1dc42e);_0x461743(_0x1dc42e);});});}exports[_0x95c8('0x16')]=function(_0x4794e8){var _0x7c533c=this;return new Promise(function(_0x4e8c05,_0x13d119){return db[_0x95c8('0x17')]['create'](_0x4794e8[_0x95c8('0x18')],{'raw':_0x4794e8[_0x95c8('0x19')]?_0x4794e8[_0x95c8('0x19')][_0x95c8('0x1a')]===undefined?!![]:![]:!![]})['then'](function(_0x39f4d8){logger['info'](_0x95c8('0x16'),_0x4794e8);logger[_0x95c8('0x11')](_0x95c8('0x16'),_0x4794e8,JSON['stringify'](_0x39f4d8));_0x4e8c05(_0x39f4d8);})[_0x95c8('0x15')](function(_0x40d7da){logger['error'](_0x95c8('0x16'),_0x40d7da[_0x95c8('0x13')],_0x4794e8);_0x13d119(_0x7c533c[_0x95c8('0x12')](0x1f4,_0x40d7da[_0x95c8('0x13')]));});});};