Built motion from commit c738b9ac.|2.6.25
[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 _0x14f1=['ids','omit','spread','AddTags','moment','bluebird','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','client','http','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','request','then','info','request\x20sent','debug','error','WhatsappInteraction,\x20%s,\x20%s','message','result','catch','WhatsappInteraction','update','options','raw','where','attributes','limit','UpdateWhatsappInteraction','stringify','AddTagsToWhatsappInteraction','find','body'];(function(_0x4f57c8,_0x32dc16){var _0x42fbf5=function(_0x42a240){while(--_0x42a240){_0x4f57c8['push'](_0x4f57c8['shift']());}};_0x42fbf5(++_0x32dc16);}(_0x14f1,0xcc));var _0x114f=function(_0x50a790,_0x851f4b){_0x50a790=_0x50a790-0x0;var _0x4833a3=_0x14f1[_0x50a790];return _0x4833a3;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x114f('0x0'));var BPromise=require(_0x114f('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x114f('0x2'));var db=require(_0x114f('0x3'))['db'];var utils=require(_0x114f('0x4'));var logger=require('../../config/logger')(_0x114f('0x5'));var config=require(_0x114f('0x6'));var jayson=require(_0x114f('0x7'));var client=jayson[_0x114f('0x8')][_0x114f('0x9')]({'port':0x232a});config[_0x114f('0xa')]=_['defaults'](config['redis'],{'host':_0x114f('0xb'),'port':0x18eb});var socket=require(_0x114f('0xc'))(new Redis(config[_0x114f('0xa')]));require(_0x114f('0xd'))['register'](socket);function respondWithRpcPromise(_0x2151e2,_0x50ae7c,_0x39a69a){return new BPromise(function(_0x4a5907,_0x491ea7){return client[_0x114f('0xe')](_0x2151e2,_0x39a69a)[_0x114f('0xf')](function(_0xf8feee){logger[_0x114f('0x10')]('WhatsappInteraction,\x20%s,\x20%s',_0x50ae7c,_0x114f('0x11'));logger[_0x114f('0x12')]('WhatsappInteraction,\x20%s,\x20%s,\x20%s',_0x50ae7c,'request\x20sent',JSON['stringify'](_0xf8feee));if(_0xf8feee[_0x114f('0x13')]){if(_0xf8feee[_0x114f('0x13')]['code']===0x1f4){logger[_0x114f('0x13')](_0x114f('0x14'),_0x50ae7c,_0xf8feee[_0x114f('0x13')][_0x114f('0x15')]);return _0x491ea7(_0xf8feee[_0x114f('0x13')]['message']);}logger[_0x114f('0x13')](_0x114f('0x14'),_0x50ae7c,_0xf8feee['error'][_0x114f('0x15')]);return _0x4a5907(_0xf8feee[_0x114f('0x13')]['message']);}else{logger[_0x114f('0x10')](_0x114f('0x14'),_0x50ae7c,_0x114f('0x11'));_0x4a5907(_0xf8feee[_0x114f('0x16')][_0x114f('0x15')]);}})[_0x114f('0x17')](function(_0x42392a){logger['error']('WhatsappInteraction,\x20%s,\x20%s',_0x50ae7c,_0x42392a);_0x491ea7(_0x42392a);});});}exports['UpdateWhatsappInteraction']=function(_0x3ddd1b){var _0x2c3156=this;return new Promise(function(_0x15b0c7,_0x4062dd){return db[_0x114f('0x18')][_0x114f('0x19')](_0x3ddd1b['body'],{'raw':_0x3ddd1b[_0x114f('0x1a')]?_0x3ddd1b['options'][_0x114f('0x1b')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x3ddd1b[_0x114f('0x1a')]?_0x3ddd1b[_0x114f('0x1a')][_0x114f('0x1c')]||null:null,'attributes':_0x3ddd1b[_0x114f('0x1a')]?_0x3ddd1b['options'][_0x114f('0x1d')]||null:null,'limit':_0x3ddd1b[_0x114f('0x1a')]?_0x3ddd1b['options'][_0x114f('0x1e')]||null:null})[_0x114f('0xf')](function(_0x30f08a){logger['info']('UpdateWhatsappInteraction',_0x3ddd1b);logger[_0x114f('0x12')](_0x114f('0x1f'),_0x3ddd1b,JSON[_0x114f('0x20')](_0x30f08a));_0x15b0c7(_0x30f08a);})[_0x114f('0x17')](function(_0x9f3f54){logger[_0x114f('0x13')](_0x114f('0x1f'),_0x9f3f54[_0x114f('0x15')],_0x3ddd1b);_0x4062dd(_0x2c3156[_0x114f('0x13')](0x1f4,_0x9f3f54[_0x114f('0x15')]));});});};exports[_0x114f('0x21')]=function(_0x82ea37){return new Promise(function(_0x4cb8b4,_0x4d69c){return db[_0x114f('0x18')][_0x114f('0x22')]({'where':_0x82ea37[_0x114f('0x1a')]?_0x82ea37['options'][_0x114f('0x1c')]||null:null})[_0x114f('0xf')](function(_0x532ccb){if(_0x532ccb){return _0x532ccb['addTags'](_0x82ea37[_0x114f('0x23')][_0x114f('0x24')],_[_0x114f('0x25')](_0x82ea37[_0x114f('0x23')],[_0x114f('0x24'),'id'])||{});}})[_0x114f('0x26')](function(_0x5e7167){logger['info'](_0x114f('0x27'),_0x82ea37);logger['debug'](_0x114f('0x27'),_0x82ea37,JSON[_0x114f('0x20')](_0x5e7167));_0x4cb8b4(_0x5e7167);})[_0x114f('0x17')](function(_0x423cc3){logger[_0x114f('0x13')](_0x114f('0x27'),_0x423cc3[_0x114f('0x15')],_0x82ea37);_0x4d69c(_this['error'](0x1f4,_0x423cc3[_0x114f('0x15')]));});});};