Built motion from commit e6806ed6.|2.6.0
[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 _0xac73=['socket.io-emitter','./chatMessage.socket','request','then','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','code','error','ChatMessage,\x20%s,\x20%s','message','catch','ChatMessage','create','body','options','CreateChatMessage','lodash','util','moment','bluebird','randomstring','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','redis','defaults'];(function(_0x11dc66,_0x23b90b){var _0x3f74ce=function(_0x469f03){while(--_0x469f03){_0x11dc66['push'](_0x11dc66['shift']());}};_0x3f74ce(++_0x23b90b);}(_0xac73,0x186));var _0x3ac7=function(_0x232a39,_0x4af35a){_0x232a39=_0x232a39-0x0;var _0x53ddcd=_0xac73[_0x232a39];return _0x53ddcd;};'use strict';var _=require(_0x3ac7('0x0'));var util=require(_0x3ac7('0x1'));var moment=require(_0x3ac7('0x2'));var BPromise=require(_0x3ac7('0x3'));var rs=require(_0x3ac7('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x3ac7('0x5'));var logger=require(_0x3ac7('0x6'))(_0x3ac7('0x7'));var config=require(_0x3ac7('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x3ac7('0x9')][_0x3ac7('0xa')]({'port':0x232a});config[_0x3ac7('0xb')]=_[_0x3ac7('0xc')](config[_0x3ac7('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0x3ac7('0xd'))(new Redis(config[_0x3ac7('0xb')]));require(_0x3ac7('0xe'))['register'](socket);function respondWithRpcPromise(_0xe0c44c,_0x583f9a,_0x501fda){return new BPromise(function(_0x4e874a,_0x13b388){return client[_0x3ac7('0xf')](_0xe0c44c,_0x501fda)[_0x3ac7('0x10')](function(_0x1dccef){logger['info']('ChatMessage,\x20%s,\x20%s',_0x583f9a,_0x3ac7('0x11'));logger[_0x3ac7('0x12')](_0x3ac7('0x13'),_0x583f9a,_0x3ac7('0x11'),JSON[_0x3ac7('0x14')](_0x1dccef));if(_0x1dccef['error']){if(_0x1dccef['error'][_0x3ac7('0x15')]===0x1f4){logger[_0x3ac7('0x16')](_0x3ac7('0x17'),_0x583f9a,_0x1dccef[_0x3ac7('0x16')]['message']);return _0x13b388(_0x1dccef['error'][_0x3ac7('0x18')]);}logger[_0x3ac7('0x16')]('ChatMessage,\x20%s,\x20%s',_0x583f9a,_0x1dccef['error'][_0x3ac7('0x18')]);return _0x4e874a(_0x1dccef[_0x3ac7('0x16')][_0x3ac7('0x18')]);}else{logger['info']('ChatMessage,\x20%s,\x20%s',_0x583f9a,_0x3ac7('0x11'));_0x4e874a(_0x1dccef['result'][_0x3ac7('0x18')]);}})[_0x3ac7('0x19')](function(_0x23b32e){logger[_0x3ac7('0x16')](_0x3ac7('0x17'),_0x583f9a,_0x23b32e);_0x13b388(_0x23b32e);});});}exports['CreateChatMessage']=function(_0x144063){var _0x247a64=this;return new Promise(function(_0x38b5bb,_0x4a7984){return db[_0x3ac7('0x1a')][_0x3ac7('0x1b')](_0x144063[_0x3ac7('0x1c')],{'raw':_0x144063['options']?_0x144063[_0x3ac7('0x1d')]['raw']===undefined?!![]:![]:!![]})['then'](function(_0x53ed2e){logger['info'](_0x3ac7('0x1e'),_0x144063);logger[_0x3ac7('0x12')](_0x3ac7('0x1e'),_0x144063,JSON[_0x3ac7('0x14')](_0x53ed2e));_0x38b5bb(_0x53ed2e);})[_0x3ac7('0x19')](function(_0x526c56){logger[_0x3ac7('0x16')](_0x3ac7('0x1e'),_0x526c56['message'],_0x144063);_0x4a7984(_0x247a64['error'](0x1f4,_0x526c56[_0x3ac7('0x18')]));});});};