Built motion from commit 639a1a7f.|2.6.19
[motion2.git] / server / api / smsInteraction / smsInteraction.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 _0xbc83=['moment','randomstring','ioredis','../../mysqldb','../../config/utils','jayson/promise','client','defaults','redis','localhost','socket.io-emitter','./smsInteraction.socket','request','SmsInteraction,\x20%s,\x20%s','request\x20sent','debug','SmsInteraction,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','UpdateSmsInteraction','SmsInteraction','update','body','options','raw','where','attributes','limit','then','info','find','addTags','ids','AddTags','lodash','util'];(function(_0x46e363,_0x45d7e2){var _0x3fb059=function(_0x5e6274){while(--_0x5e6274){_0x46e363['push'](_0x46e363['shift']());}};_0x3fb059(++_0x45d7e2);}(_0xbc83,0x73));var _0x3bc8=function(_0x368edf,_0x132b95){_0x368edf=_0x368edf-0x0;var _0x11fc80=_0xbc83[_0x368edf];return _0x11fc80;};'use strict';var _=require(_0x3bc8('0x0'));var util=require(_0x3bc8('0x1'));var moment=require(_0x3bc8('0x2'));var BPromise=require('bluebird');var rs=require(_0x3bc8('0x3'));var fs=require('fs');var Redis=require(_0x3bc8('0x4'));var db=require(_0x3bc8('0x5'))['db'];var utils=require(_0x3bc8('0x6'));var logger=require('../../config/logger')('rpc');var config=require('../../config/environment');var jayson=require(_0x3bc8('0x7'));var client=jayson[_0x3bc8('0x8')]['http']({'port':0x232a});config['redis']=_[_0x3bc8('0x9')](config[_0x3bc8('0xa')],{'host':_0x3bc8('0xb'),'port':0x18eb});var socket=require(_0x3bc8('0xc'))(new Redis(config[_0x3bc8('0xa')]));require(_0x3bc8('0xd'))['register'](socket);function respondWithRpcPromise(_0x25977d,_0x36892f,_0x4d8c50){return new BPromise(function(_0x2273c4,_0x50ab46){return client[_0x3bc8('0xe')](_0x25977d,_0x4d8c50)['then'](function(_0x37597f){logger['info'](_0x3bc8('0xf'),_0x36892f,_0x3bc8('0x10'));logger[_0x3bc8('0x11')](_0x3bc8('0x12'),_0x36892f,_0x3bc8('0x10'),JSON[_0x3bc8('0x13')](_0x37597f));if(_0x37597f[_0x3bc8('0x14')]){if(_0x37597f[_0x3bc8('0x14')]['code']===0x1f4){logger[_0x3bc8('0x14')](_0x3bc8('0xf'),_0x36892f,_0x37597f[_0x3bc8('0x14')][_0x3bc8('0x15')]);return _0x50ab46(_0x37597f['error']['message']);}logger[_0x3bc8('0x14')]('SmsInteraction,\x20%s,\x20%s',_0x36892f,_0x37597f[_0x3bc8('0x14')][_0x3bc8('0x15')]);return _0x2273c4(_0x37597f['error'][_0x3bc8('0x15')]);}else{logger['info']('SmsInteraction,\x20%s,\x20%s',_0x36892f,'request\x20sent');_0x2273c4(_0x37597f[_0x3bc8('0x16')]['message']);}})[_0x3bc8('0x17')](function(_0x190427){logger[_0x3bc8('0x14')](_0x3bc8('0xf'),_0x36892f,_0x190427);_0x50ab46(_0x190427);});});}exports[_0x3bc8('0x18')]=function(_0x13e1d1){var _0x4c6db1=this;return new Promise(function(_0x2d962a,_0x49785d){return db[_0x3bc8('0x19')][_0x3bc8('0x1a')](_0x13e1d1[_0x3bc8('0x1b')],{'raw':_0x13e1d1[_0x3bc8('0x1c')]?_0x13e1d1[_0x3bc8('0x1c')][_0x3bc8('0x1d')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x13e1d1[_0x3bc8('0x1c')]?_0x13e1d1[_0x3bc8('0x1c')][_0x3bc8('0x1e')]||null:null,'attributes':_0x13e1d1['options']?_0x13e1d1[_0x3bc8('0x1c')][_0x3bc8('0x1f')]||null:null,'limit':_0x13e1d1['options']?_0x13e1d1[_0x3bc8('0x1c')][_0x3bc8('0x20')]||null:null})[_0x3bc8('0x21')](function(_0x24c3a3){logger[_0x3bc8('0x22')](_0x3bc8('0x18'),_0x13e1d1);logger[_0x3bc8('0x11')](_0x3bc8('0x18'),_0x13e1d1,JSON['stringify'](_0x24c3a3));_0x2d962a(_0x24c3a3);})[_0x3bc8('0x17')](function(_0x57da98){logger[_0x3bc8('0x14')](_0x3bc8('0x18'),_0x57da98[_0x3bc8('0x15')],_0x13e1d1);_0x49785d(_0x4c6db1[_0x3bc8('0x14')](0x1f4,_0x57da98['message']));});});};exports['AddTagsToSmsInteraction']=function(_0x599954){return new Promise(function(_0x37dc0c,_0x313feb){return db[_0x3bc8('0x19')][_0x3bc8('0x23')]({'where':_0x599954['options']?_0x599954[_0x3bc8('0x1c')]['where']||null:null})[_0x3bc8('0x21')](function(_0x8fa861){if(_0x8fa861){return _0x8fa861[_0x3bc8('0x24')](_0x599954[_0x3bc8('0x1b')][_0x3bc8('0x25')],_['omit'](_0x599954[_0x3bc8('0x1b')],[_0x3bc8('0x25'),'id'])||{});}})['spread'](function(_0x266ec4){logger[_0x3bc8('0x22')](_0x3bc8('0x26'),_0x599954);logger[_0x3bc8('0x11')](_0x3bc8('0x26'),_0x599954,JSON[_0x3bc8('0x13')](_0x266ec4));_0x37dc0c(_0x266ec4);})[_0x3bc8('0x17')](function(_0xae73b0){logger['error']('AddTags',_0xae73b0[_0x3bc8('0x15')],_0x599954);_0x313feb(_this[_0x3bc8('0x14')](0x1f4,_0xae73b0[_0x3bc8('0x15')]));});});};