4440f2fdf5e9f3beeb2c9b19a2478d86154266c1
[motion2.git] / server / api / squareMessage / squareMessage.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 _0x5a74=['CreateSquareMessage','lodash','moment','bluebird','randomstring','ioredis','then','info','SquareMessage,\x20%s,\x20%s','request\x20sent','debug','SquareMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','SquareMessage','body','options','raw'];(function(_0xa464c9,_0x7c86d8){var _0x3d73c4=function(_0x5c2056){while(--_0x5c2056){_0xa464c9['push'](_0xa464c9['shift']());}};_0x3d73c4(++_0x7c86d8);}(_0x5a74,0x7f));var _0x45a7=function(_0x24d24e,_0x4e17a4){_0x24d24e=_0x24d24e-0x0;var _0x20e068=_0x5a74[_0x24d24e];return _0x20e068;};'use strict';var _=require(_0x45a7('0x0'));var util=require('util');var moment=require(_0x45a7('0x1'));var BPromise=require(_0x45a7('0x2'));var rs=require(_0x45a7('0x3'));var fs=require('fs');var Redis=require(_0x45a7('0x4'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')('rpc');var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x3a725a,_0x578056,_0x1d7416){return new BPromise(function(_0x38247c,_0x2acf92){return client['request'](_0x3a725a,_0x1d7416)[_0x45a7('0x5')](function(_0x2aa8e3){logger[_0x45a7('0x6')](_0x45a7('0x7'),_0x578056,_0x45a7('0x8'));logger[_0x45a7('0x9')](_0x45a7('0xa'),_0x578056,'request\x20sent',JSON[_0x45a7('0xb')](_0x2aa8e3));if(_0x2aa8e3[_0x45a7('0xc')]){if(_0x2aa8e3['error'][_0x45a7('0xd')]===0x1f4){logger[_0x45a7('0xc')](_0x45a7('0x7'),_0x578056,_0x2aa8e3['error'][_0x45a7('0xe')]);return _0x2acf92(_0x2aa8e3[_0x45a7('0xc')][_0x45a7('0xe')]);}logger['error'](_0x45a7('0x7'),_0x578056,_0x2aa8e3[_0x45a7('0xc')][_0x45a7('0xe')]);return _0x38247c(_0x2aa8e3['error']['message']);}else{logger[_0x45a7('0x6')]('SquareMessage,\x20%s,\x20%s',_0x578056,_0x45a7('0x8'));_0x38247c(_0x2aa8e3[_0x45a7('0xf')]['message']);}})['catch'](function(_0x40dfc4){logger[_0x45a7('0xc')](_0x45a7('0x7'),_0x578056,_0x40dfc4);_0x2acf92(_0x40dfc4);});});}exports['CreateSquareMessage']=function(_0x20e7b6){var _0x4e20d8=this;return new Promise(function(_0x324f28,_0x1dbe73){return db[_0x45a7('0x10')]['create'](_0x20e7b6[_0x45a7('0x11')],{'raw':_0x20e7b6[_0x45a7('0x12')]?_0x20e7b6['options'][_0x45a7('0x13')]===undefined?!![]:![]:!![]})[_0x45a7('0x5')](function(_0x7e09b2){logger['info']('CreateSquareMessage',_0x20e7b6);logger[_0x45a7('0x9')](_0x45a7('0x14'),_0x20e7b6,JSON[_0x45a7('0xb')](_0x7e09b2));_0x324f28(_0x7e09b2);})['catch'](function(_0x27fe96){logger[_0x45a7('0xc')]('CreateSquareMessage',_0x27fe96[_0x45a7('0xe')],_0x20e7b6);_0x1dbe73(_0x4e20d8[_0x45a7('0xc')](0x1f4,_0x27fe96['message']));});});};