1742f734480920a94a9e2eb1b40eb4737695fa51
[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 _0x7c24=['bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','defaults','localhost','socket.io-emitter','redis','./chatMessage.socket','register','ChatMessage,\x20%s,\x20%s','request\x20sent','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','create','options','raw','then','debug','CreateChatMessage','lodash','util','moment'];(function(_0x27af45,_0x1b57aa){var _0x18df21=function(_0x4b7679){while(--_0x4b7679){_0x27af45['push'](_0x27af45['shift']());}};_0x18df21(++_0x1b57aa);}(_0x7c24,0xf9));var _0x47c2=function(_0x2c7618,_0x26be9c){_0x2c7618=_0x2c7618-0x0;var _0x5ce3f0=_0x7c24[_0x2c7618];return _0x5ce3f0;};'use strict';var _=require(_0x47c2('0x0'));var util=require(_0x47c2('0x1'));var moment=require(_0x47c2('0x2'));var BPromise=require(_0x47c2('0x3'));var rs=require(_0x47c2('0x4'));var fs=require('fs');var Redis=require(_0x47c2('0x5'));var db=require(_0x47c2('0x6'))['db'];var utils=require(_0x47c2('0x7'));var logger=require(_0x47c2('0x8'))(_0x47c2('0x9'));var config=require(_0x47c2('0xa'));var jayson=require(_0x47c2('0xb'));var client=jayson[_0x47c2('0xc')][_0x47c2('0xd')]({'port':0x232a});config['redis']=_[_0x47c2('0xe')](config['redis'],{'host':_0x47c2('0xf'),'port':0x18eb});var socket=require(_0x47c2('0x10'))(new Redis(config[_0x47c2('0x11')]));require(_0x47c2('0x12'))[_0x47c2('0x13')](socket);function respondWithRpcPromise(_0x40c88a,_0x398bc8,_0xd84fcc){return new BPromise(function(_0x1dd2d9,_0x5554f2){return client['request'](_0x40c88a,_0xd84fcc)['then'](function(_0x27749e){logger['info'](_0x47c2('0x14'),_0x398bc8,_0x47c2('0x15'));logger['debug'](_0x47c2('0x16'),_0x398bc8,_0x47c2('0x15'),JSON[_0x47c2('0x17')](_0x27749e));if(_0x27749e[_0x47c2('0x18')]){if(_0x27749e[_0x47c2('0x18')][_0x47c2('0x19')]===0x1f4){logger[_0x47c2('0x18')]('ChatMessage,\x20%s,\x20%s',_0x398bc8,_0x27749e[_0x47c2('0x18')][_0x47c2('0x1a')]);return _0x5554f2(_0x27749e['error'][_0x47c2('0x1a')]);}logger[_0x47c2('0x18')](_0x47c2('0x14'),_0x398bc8,_0x27749e[_0x47c2('0x18')][_0x47c2('0x1a')]);return _0x1dd2d9(_0x27749e[_0x47c2('0x18')][_0x47c2('0x1a')]);}else{logger[_0x47c2('0x1b')](_0x47c2('0x14'),_0x398bc8,_0x47c2('0x15'));_0x1dd2d9(_0x27749e[_0x47c2('0x1c')][_0x47c2('0x1a')]);}})[_0x47c2('0x1d')](function(_0x4799b5){logger[_0x47c2('0x18')](_0x47c2('0x14'),_0x398bc8,_0x4799b5);_0x5554f2(_0x4799b5);});});}exports['CreateChatMessage']=function(_0x4fb528){var _0x2c2bf2=this;return new Promise(function(_0x2a8fed,_0x2eaf3e){return db['ChatMessage'][_0x47c2('0x1e')](_0x4fb528['body'],{'raw':_0x4fb528['options']?_0x4fb528[_0x47c2('0x1f')][_0x47c2('0x20')]===undefined?!![]:![]:!![]})[_0x47c2('0x21')](function(_0x242890){logger[_0x47c2('0x1b')]('CreateChatMessage',_0x4fb528);logger[_0x47c2('0x22')](_0x47c2('0x23'),_0x4fb528,JSON[_0x47c2('0x17')](_0x242890));_0x2a8fed(_0x242890);})['catch'](function(_0x5870ff){logger[_0x47c2('0x18')](_0x47c2('0x23'),_0x5870ff[_0x47c2('0x1a')],_0x4fb528);_0x2eaf3e(_0x2c2bf2[_0x47c2('0x18')](0x1f4,_0x5870ff[_0x47c2('0x1a')]));});});};