Built motion from commit ffdca78c.|2.6.24
[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 _0xb194=['request','then','ChatMessage,\x20%s,\x20%s','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','request\x20sent','result','catch','ChatMessage','create','options','raw','CreateChatMessage','lodash','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','jayson/promise','http','defaults','redis','localhost','./chatMessage.socket'];(function(_0x4d62cc,_0x1e1bd9){var _0x3202f1=function(_0x1817e6){while(--_0x1817e6){_0x4d62cc['push'](_0x4d62cc['shift']());}};_0x3202f1(++_0x1e1bd9);}(_0xb194,0x1b2));var _0x4b19=function(_0x168dab,_0x4abfce){_0x168dab=_0x168dab-0x0;var _0x166a20=_0xb194[_0x168dab];return _0x166a20;};'use strict';var _=require(_0x4b19('0x0'));var util=require('util');var moment=require(_0x4b19('0x1'));var BPromise=require(_0x4b19('0x2'));var rs=require(_0x4b19('0x3'));var fs=require('fs');var Redis=require(_0x4b19('0x4'));var db=require(_0x4b19('0x5'))['db'];var utils=require('../../config/utils');var logger=require(_0x4b19('0x6'))(_0x4b19('0x7'));var config=require('../../config/environment');var jayson=require(_0x4b19('0x8'));var client=jayson['client'][_0x4b19('0x9')]({'port':0x232a});config['redis']=_[_0x4b19('0xa')](config[_0x4b19('0xb')],{'host':_0x4b19('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x4b19('0xd'))['register'](socket);function respondWithRpcPromise(_0x10b04f,_0x9a376d,_0xac7611){return new BPromise(function(_0x211f44,_0x3b74ad){return client[_0x4b19('0xe')](_0x10b04f,_0xac7611)[_0x4b19('0xf')](function(_0x32f16e){logger['info'](_0x4b19('0x10'),_0x9a376d,'request\x20sent');logger[_0x4b19('0x11')](_0x4b19('0x12'),_0x9a376d,'request\x20sent',JSON[_0x4b19('0x13')](_0x32f16e));if(_0x32f16e['error']){if(_0x32f16e[_0x4b19('0x14')][_0x4b19('0x15')]===0x1f4){logger[_0x4b19('0x14')](_0x4b19('0x10'),_0x9a376d,_0x32f16e[_0x4b19('0x14')]['message']);return _0x3b74ad(_0x32f16e[_0x4b19('0x14')][_0x4b19('0x16')]);}logger[_0x4b19('0x14')](_0x4b19('0x10'),_0x9a376d,_0x32f16e[_0x4b19('0x14')][_0x4b19('0x16')]);return _0x211f44(_0x32f16e['error'][_0x4b19('0x16')]);}else{logger[_0x4b19('0x17')](_0x4b19('0x10'),_0x9a376d,_0x4b19('0x18'));_0x211f44(_0x32f16e[_0x4b19('0x19')][_0x4b19('0x16')]);}})[_0x4b19('0x1a')](function(_0x26a164){logger['error'](_0x4b19('0x10'),_0x9a376d,_0x26a164);_0x3b74ad(_0x26a164);});});}exports['CreateChatMessage']=function(_0x81a5f3){var _0x20ded8=this;return new Promise(function(_0x3f1ba5,_0x2f2082){return db[_0x4b19('0x1b')][_0x4b19('0x1c')](_0x81a5f3['body'],{'raw':_0x81a5f3[_0x4b19('0x1d')]?_0x81a5f3['options'][_0x4b19('0x1e')]===undefined?!![]:![]:!![]})[_0x4b19('0xf')](function(_0x234632){logger['info'](_0x4b19('0x1f'),_0x81a5f3);logger['debug'](_0x4b19('0x1f'),_0x81a5f3,JSON[_0x4b19('0x13')](_0x234632));_0x3f1ba5(_0x234632);})['catch'](function(_0x363165){logger[_0x4b19('0x14')](_0x4b19('0x1f'),_0x363165[_0x4b19('0x16')],_0x81a5f3);_0x2f2082(_0x20ded8['error'](0x1f4,_0x363165[_0x4b19('0x16')]));});});};