Built motion from commit 753c950e.|2.5.42
[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 _0x8e89=['defaults','localhost','socket.io-emitter','./whatsappInteraction.socket','register','info','request\x20sent','debug','WhatsappInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','WhatsappInteraction,\x20%s,\x20%s','message','catch','WhatsappInteraction','body','options','raw','where','limit','then','UpdateWhatsappInteraction','AddTagsToWhatsappInteraction','addTags','ids','spread','AddTags','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','http','redis'];(function(_0x1cbb47,_0xd3a7b1){var _0x52a8f9=function(_0x3ad275){while(--_0x3ad275){_0x1cbb47['push'](_0x1cbb47['shift']());}};_0x52a8f9(++_0xd3a7b1);}(_0x8e89,0x8b));var _0x98e8=function(_0xcfeff4,_0x3f2e19){_0xcfeff4=_0xcfeff4-0x0;var _0xb2fadc=_0x8e89[_0xcfeff4];return _0xb2fadc;};'use strict';var _=require('lodash');var util=require(_0x98e8('0x0'));var moment=require(_0x98e8('0x1'));var BPromise=require('bluebird');var rs=require(_0x98e8('0x2'));var fs=require('fs');var Redis=require(_0x98e8('0x3'));var db=require(_0x98e8('0x4'))['db'];var utils=require(_0x98e8('0x5'));var logger=require('../../config/logger')(_0x98e8('0x6'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson['client'][_0x98e8('0x7')]({'port':0x232a});config[_0x98e8('0x8')]=_[_0x98e8('0x9')](config[_0x98e8('0x8')],{'host':_0x98e8('0xa'),'port':0x18eb});var socket=require(_0x98e8('0xb'))(new Redis(config[_0x98e8('0x8')]));require(_0x98e8('0xc'))[_0x98e8('0xd')](socket);function respondWithRpcPromise(_0x1435a9,_0x1b345d,_0xf0f4ae){return new BPromise(function(_0x50b878,_0x40548d){return client['request'](_0x1435a9,_0xf0f4ae)['then'](function(_0xa02736){logger[_0x98e8('0xe')]('WhatsappInteraction,\x20%s,\x20%s',_0x1b345d,_0x98e8('0xf'));logger[_0x98e8('0x10')](_0x98e8('0x11'),_0x1b345d,'request\x20sent',JSON[_0x98e8('0x12')](_0xa02736));if(_0xa02736['error']){if(_0xa02736[_0x98e8('0x13')][_0x98e8('0x14')]===0x1f4){logger['error'](_0x98e8('0x15'),_0x1b345d,_0xa02736[_0x98e8('0x13')][_0x98e8('0x16')]);return _0x40548d(_0xa02736[_0x98e8('0x13')][_0x98e8('0x16')]);}logger[_0x98e8('0x13')](_0x98e8('0x15'),_0x1b345d,_0xa02736['error'][_0x98e8('0x16')]);return _0x50b878(_0xa02736[_0x98e8('0x13')][_0x98e8('0x16')]);}else{logger[_0x98e8('0xe')](_0x98e8('0x15'),_0x1b345d,_0x98e8('0xf'));_0x50b878(_0xa02736['result'][_0x98e8('0x16')]);}})[_0x98e8('0x17')](function(_0x254372){logger[_0x98e8('0x13')](_0x98e8('0x15'),_0x1b345d,_0x254372);_0x40548d(_0x254372);});});}exports['UpdateWhatsappInteraction']=function(_0x407673){var _0x48234c=this;return new Promise(function(_0x571858,_0x5b6d67){return db[_0x98e8('0x18')]['update'](_0x407673[_0x98e8('0x19')],{'raw':_0x407673[_0x98e8('0x1a')]?_0x407673['options'][_0x98e8('0x1b')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x407673['options']?_0x407673[_0x98e8('0x1a')][_0x98e8('0x1c')]||null:null,'attributes':_0x407673[_0x98e8('0x1a')]?_0x407673[_0x98e8('0x1a')]['attributes']||null:null,'limit':_0x407673['options']?_0x407673['options'][_0x98e8('0x1d')]||null:null})[_0x98e8('0x1e')](function(_0x24f2ec){logger[_0x98e8('0xe')](_0x98e8('0x1f'),_0x407673);logger[_0x98e8('0x10')](_0x98e8('0x1f'),_0x407673,JSON[_0x98e8('0x12')](_0x24f2ec));_0x571858(_0x24f2ec);})['catch'](function(_0x46fdd8){logger['error']('UpdateWhatsappInteraction',_0x46fdd8[_0x98e8('0x16')],_0x407673);_0x5b6d67(_0x48234c[_0x98e8('0x13')](0x1f4,_0x46fdd8[_0x98e8('0x16')]));});});};exports[_0x98e8('0x20')]=function(_0x1da390){return new Promise(function(_0x2c45d7,_0x41c952){return db['WhatsappInteraction']['find']({'where':_0x1da390[_0x98e8('0x1a')]?_0x1da390[_0x98e8('0x1a')][_0x98e8('0x1c')]||null:null})[_0x98e8('0x1e')](function(_0x2d0172){if(_0x2d0172){return _0x2d0172[_0x98e8('0x21')](_0x1da390['body'][_0x98e8('0x22')],_['omit'](_0x1da390[_0x98e8('0x19')],['ids','id'])||{});}})[_0x98e8('0x23')](function(_0x46fcfc){logger[_0x98e8('0xe')](_0x98e8('0x24'),_0x1da390);logger[_0x98e8('0x10')](_0x98e8('0x24'),_0x1da390,JSON[_0x98e8('0x12')](_0x46fcfc));_0x2c45d7(_0x46fcfc);})[_0x98e8('0x17')](function(_0x281a90){logger[_0x98e8('0x13')](_0x98e8('0x24'),_0x281a90[_0x98e8('0x16')],_0x1da390);_0x41c952(_this[_0x98e8('0x13')](0x1f4,_0x281a90[_0x98e8('0x16')]));});});};