Built motion from commit da617fac.|2.6.6
[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 _0x7b82=['result','catch','CreateSquareMessage','SquareMessage','options','then','moment','randomstring','../../mysqldb','../../config/utils','rpc','jayson/promise','info','SquareMessage,\x20%s,\x20%s','debug','stringify','error','message'];(function(_0x1275fe,_0xee2c86){var _0x57db9d=function(_0xb2f944){while(--_0xb2f944){_0x1275fe['push'](_0x1275fe['shift']());}};_0x57db9d(++_0xee2c86);}(_0x7b82,0xa8));var _0x27b8=function(_0x100e36,_0x4da225){_0x100e36=_0x100e36-0x0;var _0x1df0c9=_0x7b82[_0x100e36];return _0x1df0c9;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x27b8('0x0'));var BPromise=require('bluebird');var rs=require(_0x27b8('0x1'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x27b8('0x2'))['db'];var utils=require(_0x27b8('0x3'));var logger=require('../../config/logger')(_0x27b8('0x4'));var config=require('../../config/environment');var jayson=require(_0x27b8('0x5'));var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x3ee26b,_0x5b23c6,_0x5f5b36){return new BPromise(function(_0x3fdfa7,_0x36fabb){return client['request'](_0x3ee26b,_0x5f5b36)['then'](function(_0x4cf2c3){logger[_0x27b8('0x6')](_0x27b8('0x7'),_0x5b23c6,'request\x20sent');logger[_0x27b8('0x8')]('SquareMessage,\x20%s,\x20%s,\x20%s',_0x5b23c6,'request\x20sent',JSON[_0x27b8('0x9')](_0x4cf2c3));if(_0x4cf2c3[_0x27b8('0xa')]){if(_0x4cf2c3[_0x27b8('0xa')]['code']===0x1f4){logger[_0x27b8('0xa')](_0x27b8('0x7'),_0x5b23c6,_0x4cf2c3[_0x27b8('0xa')]['message']);return _0x36fabb(_0x4cf2c3['error']['message']);}logger['error'](_0x27b8('0x7'),_0x5b23c6,_0x4cf2c3[_0x27b8('0xa')][_0x27b8('0xb')]);return _0x3fdfa7(_0x4cf2c3['error'][_0x27b8('0xb')]);}else{logger[_0x27b8('0x6')](_0x27b8('0x7'),_0x5b23c6,'request\x20sent');_0x3fdfa7(_0x4cf2c3[_0x27b8('0xc')]['message']);}})[_0x27b8('0xd')](function(_0x4907d6){logger[_0x27b8('0xa')](_0x27b8('0x7'),_0x5b23c6,_0x4907d6);_0x36fabb(_0x4907d6);});});}exports[_0x27b8('0xe')]=function(_0x2f8e76){var _0x9cc703=this;return new Promise(function(_0x487fcc,_0x2cb3a3){return db[_0x27b8('0xf')]['create'](_0x2f8e76['body'],{'raw':_0x2f8e76[_0x27b8('0x10')]?_0x2f8e76[_0x27b8('0x10')]['raw']===undefined?!![]:![]:!![]})[_0x27b8('0x11')](function(_0x28b567){logger[_0x27b8('0x6')]('CreateSquareMessage',_0x2f8e76);logger[_0x27b8('0x8')](_0x27b8('0xe'),_0x2f8e76,JSON['stringify'](_0x28b567));_0x487fcc(_0x28b567);})[_0x27b8('0xd')](function(_0x119c21){logger[_0x27b8('0xa')](_0x27b8('0xe'),_0x119c21[_0x27b8('0xb')],_0x2f8e76);_0x2cb3a3(_0x9cc703[_0x27b8('0xa')](0x1f4,_0x119c21[_0x27b8('0xb')]));});});};