Built motion from commit a679711e.|2.6.15
[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 _0x7e96=['info','WhatsappInteraction,\x20%s,\x20%s','request\x20sent','error','message','result','UpdateWhatsappInteraction','WhatsappInteraction','update','body','raw','options','attributes','debug','catch','find','ids','spread','AddTags','moment','bluebird','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','defaults','localhost','socket.io-emitter','redis','./whatsappInteraction.socket','request','then'];(function(_0x42245d,_0x51758f){var _0x4b211a=function(_0x2634e){while(--_0x2634e){_0x42245d['push'](_0x42245d['shift']());}};_0x4b211a(++_0x51758f);}(_0x7e96,0x1ab));var _0x67e9=function(_0x2e3097,_0x457ec2){_0x2e3097=_0x2e3097-0x0;var _0x5c19bb=_0x7e96[_0x2e3097];return _0x5c19bb;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x67e9('0x0'));var BPromise=require(_0x67e9('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x67e9('0x2'))['db'];var utils=require(_0x67e9('0x3'));var logger=require(_0x67e9('0x4'))(_0x67e9('0x5'));var config=require(_0x67e9('0x6'));var jayson=require(_0x67e9('0x7'));var client=jayson['client']['http']({'port':0x232a});config['redis']=_[_0x67e9('0x8')](config['redis'],{'host':_0x67e9('0x9'),'port':0x18eb});var socket=require(_0x67e9('0xa'))(new Redis(config[_0x67e9('0xb')]));require(_0x67e9('0xc'))['register'](socket);function respondWithRpcPromise(_0x19a3a6,_0x1d1c56,_0x43138c){return new BPromise(function(_0x311281,_0x530b14){return client[_0x67e9('0xd')](_0x19a3a6,_0x43138c)[_0x67e9('0xe')](function(_0x349ee3){logger[_0x67e9('0xf')](_0x67e9('0x10'),_0x1d1c56,'request\x20sent');logger['debug']('WhatsappInteraction,\x20%s,\x20%s,\x20%s',_0x1d1c56,_0x67e9('0x11'),JSON['stringify'](_0x349ee3));if(_0x349ee3['error']){if(_0x349ee3[_0x67e9('0x12')]['code']===0x1f4){logger['error'](_0x67e9('0x10'),_0x1d1c56,_0x349ee3['error'][_0x67e9('0x13')]);return _0x530b14(_0x349ee3[_0x67e9('0x12')][_0x67e9('0x13')]);}logger[_0x67e9('0x12')](_0x67e9('0x10'),_0x1d1c56,_0x349ee3[_0x67e9('0x12')][_0x67e9('0x13')]);return _0x311281(_0x349ee3['error'][_0x67e9('0x13')]);}else{logger[_0x67e9('0xf')](_0x67e9('0x10'),_0x1d1c56,_0x67e9('0x11'));_0x311281(_0x349ee3[_0x67e9('0x14')][_0x67e9('0x13')]);}})['catch'](function(_0x5a101e){logger['error'](_0x67e9('0x10'),_0x1d1c56,_0x5a101e);_0x530b14(_0x5a101e);});});}exports[_0x67e9('0x15')]=function(_0x28309e){var _0xa76971=this;return new Promise(function(_0x50994f,_0x4b021e){return db[_0x67e9('0x16')][_0x67e9('0x17')](_0x28309e[_0x67e9('0x18')],{'raw':_0x28309e['options']?_0x28309e['options'][_0x67e9('0x19')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x28309e[_0x67e9('0x1a')]?_0x28309e[_0x67e9('0x1a')]['where']||null:null,'attributes':_0x28309e[_0x67e9('0x1a')]?_0x28309e[_0x67e9('0x1a')][_0x67e9('0x1b')]||null:null,'limit':_0x28309e['options']?_0x28309e[_0x67e9('0x1a')]['limit']||null:null})[_0x67e9('0xe')](function(_0x1eaf5f){logger[_0x67e9('0xf')](_0x67e9('0x15'),_0x28309e);logger[_0x67e9('0x1c')]('UpdateWhatsappInteraction',_0x28309e,JSON['stringify'](_0x1eaf5f));_0x50994f(_0x1eaf5f);})[_0x67e9('0x1d')](function(_0x36aee9){logger['error'](_0x67e9('0x15'),_0x36aee9[_0x67e9('0x13')],_0x28309e);_0x4b021e(_0xa76971[_0x67e9('0x12')](0x1f4,_0x36aee9[_0x67e9('0x13')]));});});};exports['AddTagsToWhatsappInteraction']=function(_0x401ec9){return new Promise(function(_0x1f46f0,_0x25cfe6){return db[_0x67e9('0x16')][_0x67e9('0x1e')]({'where':_0x401ec9[_0x67e9('0x1a')]?_0x401ec9['options']['where']||null:null})[_0x67e9('0xe')](function(_0x6d2d11){if(_0x6d2d11){return _0x6d2d11['addTags'](_0x401ec9[_0x67e9('0x18')][_0x67e9('0x1f')],_['omit'](_0x401ec9[_0x67e9('0x18')],[_0x67e9('0x1f'),'id'])||{});}})[_0x67e9('0x20')](function(_0x3d4d4f){logger[_0x67e9('0xf')](_0x67e9('0x21'),_0x401ec9);logger['debug'](_0x67e9('0x21'),_0x401ec9,JSON['stringify'](_0x3d4d4f));_0x1f46f0(_0x3d4d4f);})[_0x67e9('0x1d')](function(_0x167985){logger[_0x67e9('0x12')]('AddTags',_0x167985[_0x67e9('0x13')],_0x401ec9);_0x25cfe6(_this[_0x67e9('0x12')](0x1f4,_0x167985['message']));});});};