979c2c49510eee0391759cbcc9ef327834000993
[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 _0x0f32=['request','then','SquareMessage,\x20%s,\x20%s','request\x20sent','debug','SquareMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','CreateSquareMessage','body','options','raw','catch','lodash','util','bluebird','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http'];(function(_0xfdf0d6,_0x1a4a90){var _0x4e62ae=function(_0x16d2f2){while(--_0x16d2f2){_0xfdf0d6['push'](_0xfdf0d6['shift']());}};_0x4e62ae(++_0x1a4a90);}(_0x0f32,0x65));var _0x20f3=function(_0x36472e,_0x76ab32){_0x36472e=_0x36472e-0x0;var _0x472122=_0x0f32[_0x36472e];return _0x472122;};'use strict';var _=require(_0x20f3('0x0'));var util=require(_0x20f3('0x1'));var moment=require('moment');var BPromise=require(_0x20f3('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x20f3('0x3'));var db=require(_0x20f3('0x4'))['db'];var utils=require(_0x20f3('0x5'));var logger=require(_0x20f3('0x6'))(_0x20f3('0x7'));var config=require(_0x20f3('0x8'));var jayson=require(_0x20f3('0x9'));var client=jayson['client'][_0x20f3('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x1f74ff,_0x2f90f0,_0x1ea707){return new BPromise(function(_0x34b68a,_0x2f7549){return client[_0x20f3('0xb')](_0x1f74ff,_0x1ea707)[_0x20f3('0xc')](function(_0x3674db){logger['info'](_0x20f3('0xd'),_0x2f90f0,_0x20f3('0xe'));logger[_0x20f3('0xf')](_0x20f3('0x10'),_0x2f90f0,_0x20f3('0xe'),JSON[_0x20f3('0x11')](_0x3674db));if(_0x3674db[_0x20f3('0x12')]){if(_0x3674db[_0x20f3('0x12')][_0x20f3('0x13')]===0x1f4){logger[_0x20f3('0x12')](_0x20f3('0xd'),_0x2f90f0,_0x3674db[_0x20f3('0x12')][_0x20f3('0x14')]);return _0x2f7549(_0x3674db[_0x20f3('0x12')][_0x20f3('0x14')]);}logger['error'](_0x20f3('0xd'),_0x2f90f0,_0x3674db[_0x20f3('0x12')][_0x20f3('0x14')]);return _0x34b68a(_0x3674db[_0x20f3('0x12')]['message']);}else{logger[_0x20f3('0x15')]('SquareMessage,\x20%s,\x20%s',_0x2f90f0,'request\x20sent');_0x34b68a(_0x3674db[_0x20f3('0x16')]['message']);}})['catch'](function(_0x608901){logger[_0x20f3('0x12')]('SquareMessage,\x20%s,\x20%s',_0x2f90f0,_0x608901);_0x2f7549(_0x608901);});});}exports[_0x20f3('0x17')]=function(_0x21e07b){var _0x3104eb=this;return new Promise(function(_0x140735,_0x266611){return db['SquareMessage']['create'](_0x21e07b[_0x20f3('0x18')],{'raw':_0x21e07b[_0x20f3('0x19')]?_0x21e07b['options'][_0x20f3('0x1a')]===undefined?!![]:![]:!![]})[_0x20f3('0xc')](function(_0x3719db){logger[_0x20f3('0x15')](_0x20f3('0x17'),_0x21e07b);logger[_0x20f3('0xf')](_0x20f3('0x17'),_0x21e07b,JSON[_0x20f3('0x11')](_0x3719db));_0x140735(_0x3719db);})[_0x20f3('0x1b')](function(_0x4934cd){logger[_0x20f3('0x12')](_0x20f3('0x17'),_0x4934cd[_0x20f3('0x14')],_0x21e07b);_0x266611(_0x3104eb['error'](0x1f4,_0x4934cd[_0x20f3('0x14')]));});});};