461599d370cf8119f1991e516e0e9687a6fa0934
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.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 _0x7e2a=['request','then','info','WhatsappInteraction,\x20%s,\x20%s','request\x20sent','WhatsappInteraction,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','UpdateWhatsappInteraction','WhatsappInteraction','update','body','options','where','attributes','debug','addTags','omit','ids','spread','AddTags','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','defaults','redis','localhost','socket.io-emitter','./whatsappInteraction.socket'];(function(_0xed2793,_0x2cad50){var _0x19151f=function(_0x14e089){while(--_0x14e089){_0xed2793['push'](_0xed2793['shift']());}};_0x19151f(++_0x2cad50);}(_0x7e2a,0x160));var _0xa7e2=function(_0x4d9787,_0x96d522){_0x4d9787=_0x4d9787-0x0;var _0x3b96ef=_0x7e2a[_0x4d9787];return _0x3b96ef;};'use strict';var _=require('lodash');var util=require(_0xa7e2('0x0'));var moment=require(_0xa7e2('0x1'));var BPromise=require(_0xa7e2('0x2'));var rs=require(_0xa7e2('0x3'));var fs=require('fs');var Redis=require(_0xa7e2('0x4'));var db=require(_0xa7e2('0x5'))['db'];var utils=require(_0xa7e2('0x6'));var logger=require(_0xa7e2('0x7'))(_0xa7e2('0x8'));var config=require('../../config/environment');var jayson=require(_0xa7e2('0x9'));var client=jayson[_0xa7e2('0xa')][_0xa7e2('0xb')]({'port':0x232a});config['redis']=_[_0xa7e2('0xc')](config[_0xa7e2('0xd')],{'host':_0xa7e2('0xe'),'port':0x18eb});var socket=require(_0xa7e2('0xf'))(new Redis(config[_0xa7e2('0xd')]));require(_0xa7e2('0x10'))['register'](socket);function respondWithRpcPromise(_0x3b6631,_0x318c08,_0x4e8433){return new BPromise(function(_0x50472d,_0x137846){return client[_0xa7e2('0x11')](_0x3b6631,_0x4e8433)[_0xa7e2('0x12')](function(_0xfa992b){logger[_0xa7e2('0x13')](_0xa7e2('0x14'),_0x318c08,_0xa7e2('0x15'));logger['debug'](_0xa7e2('0x16'),_0x318c08,_0xa7e2('0x15'),JSON[_0xa7e2('0x17')](_0xfa992b));if(_0xfa992b[_0xa7e2('0x18')]){if(_0xfa992b['error']['code']===0x1f4){logger[_0xa7e2('0x18')](_0xa7e2('0x14'),_0x318c08,_0xfa992b[_0xa7e2('0x18')][_0xa7e2('0x19')]);return _0x137846(_0xfa992b[_0xa7e2('0x18')][_0xa7e2('0x19')]);}logger[_0xa7e2('0x18')](_0xa7e2('0x14'),_0x318c08,_0xfa992b[_0xa7e2('0x18')][_0xa7e2('0x19')]);return _0x50472d(_0xfa992b['error'][_0xa7e2('0x19')]);}else{logger[_0xa7e2('0x13')](_0xa7e2('0x14'),_0x318c08,_0xa7e2('0x15'));_0x50472d(_0xfa992b[_0xa7e2('0x1a')][_0xa7e2('0x19')]);}})[_0xa7e2('0x1b')](function(_0x1131f3){logger['error'](_0xa7e2('0x14'),_0x318c08,_0x1131f3);_0x137846(_0x1131f3);});});}exports[_0xa7e2('0x1c')]=function(_0x449010){var _0x165139=this;return new Promise(function(_0x19e520,_0x32d7df){return db[_0xa7e2('0x1d')][_0xa7e2('0x1e')](_0x449010[_0xa7e2('0x1f')],{'raw':_0x449010[_0xa7e2('0x20')]?_0x449010['options']['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x449010[_0xa7e2('0x20')]?_0x449010[_0xa7e2('0x20')][_0xa7e2('0x21')]||null:null,'attributes':_0x449010['options']?_0x449010[_0xa7e2('0x20')][_0xa7e2('0x22')]||null:null,'limit':_0x449010[_0xa7e2('0x20')]?_0x449010[_0xa7e2('0x20')]['limit']||null:null})[_0xa7e2('0x12')](function(_0xb500cf){logger[_0xa7e2('0x13')]('UpdateWhatsappInteraction',_0x449010);logger[_0xa7e2('0x23')](_0xa7e2('0x1c'),_0x449010,JSON[_0xa7e2('0x17')](_0xb500cf));_0x19e520(_0xb500cf);})[_0xa7e2('0x1b')](function(_0x3e21a2){logger[_0xa7e2('0x18')](_0xa7e2('0x1c'),_0x3e21a2['message'],_0x449010);_0x32d7df(_0x165139[_0xa7e2('0x18')](0x1f4,_0x3e21a2[_0xa7e2('0x19')]));});});};exports['AddTagsToWhatsappInteraction']=function(_0x48a7f6){return new Promise(function(_0x2b75df,_0x4c00f0){return db[_0xa7e2('0x1d')]['find']({'where':_0x48a7f6[_0xa7e2('0x20')]?_0x48a7f6[_0xa7e2('0x20')]['where']||null:null})['then'](function(_0x92581){if(_0x92581){return _0x92581[_0xa7e2('0x24')](_0x48a7f6[_0xa7e2('0x1f')]['ids'],_[_0xa7e2('0x25')](_0x48a7f6['body'],[_0xa7e2('0x26'),'id'])||{});}})[_0xa7e2('0x27')](function(_0x5bbc62){logger[_0xa7e2('0x13')](_0xa7e2('0x28'),_0x48a7f6);logger['debug'](_0xa7e2('0x28'),_0x48a7f6,JSON[_0xa7e2('0x17')](_0x5bbc62));_0x2b75df(_0x5bbc62);})[_0xa7e2('0x1b')](function(_0x20be71){logger['error'](_0xa7e2('0x28'),_0x20be71['message'],_0x48a7f6);_0x4c00f0(_this[_0xa7e2('0x18')](0x1f4,_0x20be71[_0xa7e2('0x19')]));});});};