Built motion from commit 3d6333b4.|2.6.31
[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 _0x8031=['debug','AddTagsToSmsInteraction','find','addTags','ids','omit','spread','AddTags','lodash','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','localhost','redis','register','request','then','info','SmsInteraction,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','catch','SmsInteraction','body','options','raw','where','attributes','limit','UpdateSmsInteraction'];(function(_0x4f21a4,_0x4c3a7f){var _0x7c052c=function(_0x56a41e){while(--_0x56a41e){_0x4f21a4['push'](_0x4f21a4['shift']());}};_0x7c052c(++_0x4c3a7f);}(_0x8031,0xd5));var _0x1803=function(_0x525c7b,_0x488fcc){_0x525c7b=_0x525c7b-0x0;var _0x27b33e=_0x8031[_0x525c7b];return _0x27b33e;};'use strict';var _=require(_0x1803('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x1803('0x1'));var rs=require(_0x1803('0x2'));var fs=require('fs');var Redis=require(_0x1803('0x3'));var db=require(_0x1803('0x4'))['db'];var utils=require(_0x1803('0x5'));var logger=require(_0x1803('0x6'))(_0x1803('0x7'));var config=require(_0x1803('0x8'));var jayson=require(_0x1803('0x9'));var client=jayson[_0x1803('0xa')][_0x1803('0xb')]({'port':0x232a});config['redis']=_['defaults'](config['redis'],{'host':_0x1803('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x1803('0xd')]));require('./smsInteraction.socket')[_0x1803('0xe')](socket);function respondWithRpcPromise(_0x4f429e,_0x21036a,_0x1da345){return new BPromise(function(_0x151df9,_0x3ae2fc){return client[_0x1803('0xf')](_0x4f429e,_0x1da345)[_0x1803('0x10')](function(_0xbdb10b){logger[_0x1803('0x11')](_0x1803('0x12'),_0x21036a,_0x1803('0x13'));logger['debug']('SmsInteraction,\x20%s,\x20%s,\x20%s',_0x21036a,_0x1803('0x13'),JSON[_0x1803('0x14')](_0xbdb10b));if(_0xbdb10b[_0x1803('0x15')]){if(_0xbdb10b[_0x1803('0x15')][_0x1803('0x16')]===0x1f4){logger['error'](_0x1803('0x12'),_0x21036a,_0xbdb10b[_0x1803('0x15')][_0x1803('0x17')]);return _0x3ae2fc(_0xbdb10b['error'][_0x1803('0x17')]);}logger['error'](_0x1803('0x12'),_0x21036a,_0xbdb10b['error'][_0x1803('0x17')]);return _0x151df9(_0xbdb10b[_0x1803('0x15')][_0x1803('0x17')]);}else{logger['info']('SmsInteraction,\x20%s,\x20%s',_0x21036a,'request\x20sent');_0x151df9(_0xbdb10b['result'][_0x1803('0x17')]);}})[_0x1803('0x18')](function(_0x159225){logger[_0x1803('0x15')](_0x1803('0x12'),_0x21036a,_0x159225);_0x3ae2fc(_0x159225);});});}exports['UpdateSmsInteraction']=function(_0x879a18){var _0x17270d=this;return new Promise(function(_0x53efeb,_0x3a8bf1){return db[_0x1803('0x19')]['update'](_0x879a18[_0x1803('0x1a')],{'raw':_0x879a18[_0x1803('0x1b')]?_0x879a18[_0x1803('0x1b')][_0x1803('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x879a18[_0x1803('0x1b')]?_0x879a18['options'][_0x1803('0x1d')]||null:null,'attributes':_0x879a18[_0x1803('0x1b')]?_0x879a18[_0x1803('0x1b')][_0x1803('0x1e')]||null:null,'limit':_0x879a18[_0x1803('0x1b')]?_0x879a18['options'][_0x1803('0x1f')]||null:null})[_0x1803('0x10')](function(_0x115ca8){logger[_0x1803('0x11')](_0x1803('0x20'),_0x879a18);logger[_0x1803('0x21')](_0x1803('0x20'),_0x879a18,JSON[_0x1803('0x14')](_0x115ca8));_0x53efeb(_0x115ca8);})[_0x1803('0x18')](function(_0x497f0a){logger['error'](_0x1803('0x20'),_0x497f0a[_0x1803('0x17')],_0x879a18);_0x3a8bf1(_0x17270d[_0x1803('0x15')](0x1f4,_0x497f0a[_0x1803('0x17')]));});});};exports[_0x1803('0x22')]=function(_0x1a85cb){return new Promise(function(_0x10f8cc,_0x1b7701){return db['SmsInteraction'][_0x1803('0x23')]({'where':_0x1a85cb[_0x1803('0x1b')]?_0x1a85cb[_0x1803('0x1b')][_0x1803('0x1d')]||null:null})['then'](function(_0x468a5e){if(_0x468a5e){return _0x468a5e[_0x1803('0x24')](_0x1a85cb['body'][_0x1803('0x25')],_[_0x1803('0x26')](_0x1a85cb[_0x1803('0x1a')],['ids','id'])||{});}})[_0x1803('0x27')](function(_0x4bbc73){logger[_0x1803('0x11')]('AddTags',_0x1a85cb);logger[_0x1803('0x21')](_0x1803('0x28'),_0x1a85cb,JSON[_0x1803('0x14')](_0x4bbc73));_0x10f8cc(_0x4bbc73);})[_0x1803('0x18')](function(_0xc7af4f){logger[_0x1803('0x15')](_0x1803('0x28'),_0xc7af4f[_0x1803('0x17')],_0x1a85cb);_0x1b7701(_this[_0x1803('0x15')](0x1f4,_0xc7af4f[_0x1803('0x17')]));});});};