Built motion from commit 85328c08.|2.5.50
[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 _0xd76a=['spread','AddTags','util','moment','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','http','redis','socket.io-emitter','./whatsappInteraction.socket','register','WhatsappInteraction,\x20%s,\x20%s','request\x20sent','debug','WhatsappInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','UpdateWhatsappInteraction','WhatsappInteraction','update','body','options','raw','where','attributes','then','info','AddTagsToWhatsappInteraction','omit'];(function(_0x3336eb,_0x4bfc84){var _0x59e358=function(_0x180127){while(--_0x180127){_0x3336eb['push'](_0x3336eb['shift']());}};_0x59e358(++_0x4bfc84);}(_0xd76a,0x146));var _0xad76=function(_0x680afe,_0x27f019){_0x680afe=_0x680afe-0x0;var _0x3cb94c=_0xd76a[_0x680afe];return _0x3cb94c;};'use strict';var _=require('lodash');var util=require(_0xad76('0x0'));var moment=require(_0xad76('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0xad76('0x2'))['db'];var utils=require(_0xad76('0x3'));var logger=require(_0xad76('0x4'))(_0xad76('0x5'));var config=require(_0xad76('0x6'));var jayson=require('jayson/promise');var client=jayson['client'][_0xad76('0x7')]({'port':0x232a});config[_0xad76('0x8')]=_['defaults'](config[_0xad76('0x8')],{'host':'localhost','port':0x18eb});var socket=require(_0xad76('0x9'))(new Redis(config[_0xad76('0x8')]));require(_0xad76('0xa'))[_0xad76('0xb')](socket);function respondWithRpcPromise(_0x1c86d6,_0x19d6a2,_0x160db7){return new BPromise(function(_0x477f3f,_0x316a0e){return client['request'](_0x1c86d6,_0x160db7)['then'](function(_0x221941){logger['info'](_0xad76('0xc'),_0x19d6a2,_0xad76('0xd'));logger[_0xad76('0xe')](_0xad76('0xf'),_0x19d6a2,_0xad76('0xd'),JSON[_0xad76('0x10')](_0x221941));if(_0x221941[_0xad76('0x11')]){if(_0x221941[_0xad76('0x11')][_0xad76('0x12')]===0x1f4){logger[_0xad76('0x11')]('WhatsappInteraction,\x20%s,\x20%s',_0x19d6a2,_0x221941[_0xad76('0x11')][_0xad76('0x13')]);return _0x316a0e(_0x221941[_0xad76('0x11')]['message']);}logger[_0xad76('0x11')](_0xad76('0xc'),_0x19d6a2,_0x221941[_0xad76('0x11')][_0xad76('0x13')]);return _0x477f3f(_0x221941[_0xad76('0x11')][_0xad76('0x13')]);}else{logger['info']('WhatsappInteraction,\x20%s,\x20%s',_0x19d6a2,_0xad76('0xd'));_0x477f3f(_0x221941[_0xad76('0x14')][_0xad76('0x13')]);}})[_0xad76('0x15')](function(_0x523804){logger[_0xad76('0x11')](_0xad76('0xc'),_0x19d6a2,_0x523804);_0x316a0e(_0x523804);});});}exports[_0xad76('0x16')]=function(_0x186c77){var _0x4549a1=this;return new Promise(function(_0x5ad865,_0xe47db1){return db[_0xad76('0x17')][_0xad76('0x18')](_0x186c77[_0xad76('0x19')],{'raw':_0x186c77['options']?_0x186c77[_0xad76('0x1a')][_0xad76('0x1b')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x186c77[_0xad76('0x1a')]?_0x186c77[_0xad76('0x1a')][_0xad76('0x1c')]||null:null,'attributes':_0x186c77[_0xad76('0x1a')]?_0x186c77[_0xad76('0x1a')][_0xad76('0x1d')]||null:null,'limit':_0x186c77[_0xad76('0x1a')]?_0x186c77[_0xad76('0x1a')]['limit']||null:null})[_0xad76('0x1e')](function(_0x2914d7){logger[_0xad76('0x1f')](_0xad76('0x16'),_0x186c77);logger[_0xad76('0xe')](_0xad76('0x16'),_0x186c77,JSON[_0xad76('0x10')](_0x2914d7));_0x5ad865(_0x2914d7);})[_0xad76('0x15')](function(_0xe9f219){logger[_0xad76('0x11')]('UpdateWhatsappInteraction',_0xe9f219['message'],_0x186c77);_0xe47db1(_0x4549a1[_0xad76('0x11')](0x1f4,_0xe9f219[_0xad76('0x13')]));});});};exports[_0xad76('0x20')]=function(_0x1ff61d){return new Promise(function(_0x40bd87,_0x166b72){return db[_0xad76('0x17')]['find']({'where':_0x1ff61d[_0xad76('0x1a')]?_0x1ff61d[_0xad76('0x1a')][_0xad76('0x1c')]||null:null})[_0xad76('0x1e')](function(_0x161920){if(_0x161920){return _0x161920['addTags'](_0x1ff61d[_0xad76('0x19')]['ids'],_[_0xad76('0x21')](_0x1ff61d[_0xad76('0x19')],['ids','id'])||{});}})[_0xad76('0x22')](function(_0x4a9302){logger[_0xad76('0x1f')](_0xad76('0x23'),_0x1ff61d);logger[_0xad76('0xe')]('AddTags',_0x1ff61d,JSON[_0xad76('0x10')](_0x4a9302));_0x40bd87(_0x4a9302);})[_0xad76('0x15')](function(_0x26c4a5){logger['error']('AddTags',_0x26c4a5['message'],_0x1ff61d);_0x166b72(_this[_0xad76('0x11')](0x1f4,_0x26c4a5[_0xad76('0x13')]));});});};