Built motion from commit e02f907f.|2.6.14
[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 _0xbfb9=['catch','SmsInteraction','body','options','where','attributes','limit','UpdateSmsInteraction','find','addTags','ids','omit','AddTags','lodash','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','http','redis','defaults','localhost','./smsInteraction.socket','register','request','then','info','SmsInteraction,\x20%s,\x20%s','request\x20sent','debug','SmsInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result'];(function(_0xb4a391,_0x4ac686){var _0x33547f=function(_0x116b3c){while(--_0x116b3c){_0xb4a391['push'](_0xb4a391['shift']());}};_0x33547f(++_0x4ac686);}(_0xbfb9,0x88));var _0x9bfb=function(_0x502c7d,_0x2f1285){_0x502c7d=_0x502c7d-0x0;var _0x30b7ed=_0xbfb9[_0x502c7d];return _0x30b7ed;};'use strict';var _=require(_0x9bfb('0x0'));var util=require('util');var moment=require(_0x9bfb('0x1'));var BPromise=require(_0x9bfb('0x2'));var rs=require(_0x9bfb('0x3'));var fs=require('fs');var Redis=require(_0x9bfb('0x4'));var db=require(_0x9bfb('0x5'))['db'];var utils=require(_0x9bfb('0x6'));var logger=require('../../config/logger')(_0x9bfb('0x7'));var config=require(_0x9bfb('0x8'));var jayson=require(_0x9bfb('0x9'));var client=jayson['client'][_0x9bfb('0xa')]({'port':0x232a});config[_0x9bfb('0xb')]=_[_0x9bfb('0xc')](config[_0x9bfb('0xb')],{'host':_0x9bfb('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x9bfb('0xe'))[_0x9bfb('0xf')](socket);function respondWithRpcPromise(_0x454e74,_0x48e2d7,_0x410a72){return new BPromise(function(_0xe279eb,_0x62c612){return client[_0x9bfb('0x10')](_0x454e74,_0x410a72)[_0x9bfb('0x11')](function(_0x58b61a){logger[_0x9bfb('0x12')](_0x9bfb('0x13'),_0x48e2d7,_0x9bfb('0x14'));logger[_0x9bfb('0x15')](_0x9bfb('0x16'),_0x48e2d7,'request\x20sent',JSON[_0x9bfb('0x17')](_0x58b61a));if(_0x58b61a[_0x9bfb('0x18')]){if(_0x58b61a[_0x9bfb('0x18')][_0x9bfb('0x19')]===0x1f4){logger[_0x9bfb('0x18')]('SmsInteraction,\x20%s,\x20%s',_0x48e2d7,_0x58b61a[_0x9bfb('0x18')]['message']);return _0x62c612(_0x58b61a[_0x9bfb('0x18')][_0x9bfb('0x1a')]);}logger[_0x9bfb('0x18')](_0x9bfb('0x13'),_0x48e2d7,_0x58b61a['error']['message']);return _0xe279eb(_0x58b61a[_0x9bfb('0x18')]['message']);}else{logger[_0x9bfb('0x12')]('SmsInteraction,\x20%s,\x20%s',_0x48e2d7,_0x9bfb('0x14'));_0xe279eb(_0x58b61a[_0x9bfb('0x1b')][_0x9bfb('0x1a')]);}})[_0x9bfb('0x1c')](function(_0x3184bb){logger[_0x9bfb('0x18')]('SmsInteraction,\x20%s,\x20%s',_0x48e2d7,_0x3184bb);_0x62c612(_0x3184bb);});});}exports['UpdateSmsInteraction']=function(_0x5c987c){var _0x4d35d5=this;return new Promise(function(_0x4dd117,_0x4f740a){return db[_0x9bfb('0x1d')]['update'](_0x5c987c[_0x9bfb('0x1e')],{'raw':_0x5c987c[_0x9bfb('0x1f')]?_0x5c987c[_0x9bfb('0x1f')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x5c987c['options']?_0x5c987c['options'][_0x9bfb('0x20')]||null:null,'attributes':_0x5c987c[_0x9bfb('0x1f')]?_0x5c987c[_0x9bfb('0x1f')][_0x9bfb('0x21')]||null:null,'limit':_0x5c987c[_0x9bfb('0x1f')]?_0x5c987c['options'][_0x9bfb('0x22')]||null:null})[_0x9bfb('0x11')](function(_0x2f1b6a){logger['info'](_0x9bfb('0x23'),_0x5c987c);logger[_0x9bfb('0x15')](_0x9bfb('0x23'),_0x5c987c,JSON[_0x9bfb('0x17')](_0x2f1b6a));_0x4dd117(_0x2f1b6a);})[_0x9bfb('0x1c')](function(_0x2e01fe){logger[_0x9bfb('0x18')](_0x9bfb('0x23'),_0x2e01fe[_0x9bfb('0x1a')],_0x5c987c);_0x4f740a(_0x4d35d5[_0x9bfb('0x18')](0x1f4,_0x2e01fe['message']));});});};exports['AddTagsToSmsInteraction']=function(_0x118d2f){return new Promise(function(_0x1e9751,_0x5be396){return db['SmsInteraction'][_0x9bfb('0x24')]({'where':_0x118d2f['options']?_0x118d2f[_0x9bfb('0x1f')][_0x9bfb('0x20')]||null:null})[_0x9bfb('0x11')](function(_0x41d364){if(_0x41d364){return _0x41d364[_0x9bfb('0x25')](_0x118d2f[_0x9bfb('0x1e')][_0x9bfb('0x26')],_[_0x9bfb('0x27')](_0x118d2f['body'],[_0x9bfb('0x26'),'id'])||{});}})['spread'](function(_0x3a2892){logger[_0x9bfb('0x12')](_0x9bfb('0x28'),_0x118d2f);logger[_0x9bfb('0x15')](_0x9bfb('0x28'),_0x118d2f,JSON['stringify'](_0x3a2892));_0x1e9751(_0x3a2892);})[_0x9bfb('0x1c')](function(_0x1cfc03){logger['error']('AddTags',_0x1cfc03['message'],_0x118d2f);_0x5be396(_this[_0x9bfb('0x18')](0x1f4,_0x1cfc03[_0x9bfb('0x1a')]));});});};