4c2d69141a63ba1859249c9bc664245b1ba2d625
[motion2.git] / server / services / routing / server / applications / dialogflow.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 _0xc820=['error','moment','apiai-promise','md5','./utils','../../../../config/logger','../../rpc/chatMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','info','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','created','isEmpty','body','getMustacheRender','then','catch','finally','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','textRequest','message','dialogflow','result','fulfillment','speech','providerResponse','Message','metadata','next','stringify'];(function(_0x4944b8,_0x5ae5c9){var _0x3fb8c1=function(_0x343860){while(--_0x343860){_0x4944b8['push'](_0x4944b8['shift']());}};_0x3fb8c1(++_0x5ae5c9);}(_0xc820,0x13f));var _0x0c82=function(_0x112b84,_0x44902d){_0x112b84=_0x112b84-0x0;var _0x537739=_0xc820[_0x112b84];return _0x537739;};'use strict';var _=require('lodash');var moment=require(_0x0c82('0x0'));var apiai=require(_0x0c82('0x1'));var md5=require(_0x0c82('0x2'));var utils=require(_0x0c82('0x3'));var logger=require(_0x0c82('0x4'))('routing');var rpc={'chatMessage':require(_0x0c82('0x5')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x0c82('0x6')),'smsMessage':require(_0x0c82('0x7')),'faxMessage':require(_0x0c82('0x8')),'whatsappMessage':require(_0x0c82('0x9'))};exports[_0x0c82('0xa')]=function(_0x23f783,_0x2d2567){return function(_0x32e9ee){try{if(!_[_0x0c82('0xb')](this[_0x0c82('0xc')][_0x0c82('0xd')])){logger[_0x0c82('0xe')](_0x0c82('0xf'),_0x23f783,_0x0c82('0x10'));return _0x32e9ee['next']();}var _0x8c568={'ContactId':this[_0x0c82('0x11')]['id'],'sentAt':moment()[_0x0c82('0x12')](_0x0c82('0x13')),'direction':_0x0c82('0x14')};if(this[_0x0c82('0x15')]===_0x0c82('0x16')||this[_0x0c82('0x15')]===_0x0c82('0x17')){_0x8c568[_0x0c82('0x18')]=this['interaction'][_0x0c82('0x18')];}var _0x54b6da=this['channel'];if(_0x54b6da===_0x0c82('0x19')){_0x8c568[_0x0c82('0x1a')]=this[_0x0c82('0x1b')]['id'];}else{_0x8c568[_[_0x0c82('0x1c')](_0x54b6da)+_0x0c82('0x1d')]=this['account']['id'];}_0x8c568[_[_0x0c82('0x1c')](_0x54b6da)+_0x0c82('0x1e')]=this[_0x0c82('0xc')]['id'];if(this['interaction'][_0x0c82('0x1f')]){var _0x5d7992=_0x2d2567[0x2];if(!_[_0x0c82('0x20')](_0x5d7992)){_0x8c568[_0x0c82('0x21')]=utils[_0x0c82('0x22')](_0x5d7992,this);return rpc[_0x54b6da+'Message']['create'](_0x8c568)[_0x0c82('0x23')](function(_0x3dbfd1){logger['info'](_0x0c82('0xf'),_0x23f783,_0x8c568['body']);})[_0x0c82('0x24')](function(_0x3aa4c3){logger['error'](_0x0c82('0xf'),_0x23f783,JSON['stringify'](_0x3aa4c3));})[_0x0c82('0x25')](function(){logger['info'](_0x0c82('0x26'),_0x23f783);_0x32e9ee[_0x0c82('0x27')]();});}else{logger['info'](_0x0c82('0x28'),_0x23f783);_0x32e9ee[_0x0c82('0x27')]();}}else{var _0x8a6e02=this;var _0x4a4a04=apiai(_0x2d2567[0x0],{'language':_0x2d2567[0x1]||'en'});return _0x4a4a04[_0x0c82('0x29')](this[_0x0c82('0x2a')][_0x0c82('0x21')],{'sessionId':md5(this[_0x0c82('0xc')]['id'])})['then'](function(_0x2bcc7f){_0x8a6e02[_0x0c82('0x21')][_0x0c82('0x2b')]=_0x2bcc7f;_0x8c568[_0x0c82('0x21')]=_0x2bcc7f[_0x0c82('0x2c')][_0x0c82('0x2d')][_0x0c82('0x2e')];_0x8c568['providerName']=_0x0c82('0x2b');_0x8c568[_0x0c82('0x2f')]=JSON['stringify'](_0x2bcc7f);return rpc[_0x54b6da+_0x0c82('0x30')]['create'](_0x8c568)['then'](function(_0xde34d0){logger[_0x0c82('0xe')](_0x0c82('0xf'),_0x23f783,_0x8c568[_0x0c82('0x21')]);if(_0x2bcc7f[_0x0c82('0x2c')][_0x0c82('0x31')]['endConversation']){_0x32e9ee[_0x0c82('0x32')]();}else{_0x32e9ee['stop']();}})['catch'](function(_0x17b569){logger['error']('[%s][DIALOGFLOW]\x20%s',_0x23f783,JSON[_0x0c82('0x33')](_0x17b569));_0x32e9ee['next']();});})['catch'](function(_0x566e08){logger[_0x0c82('0x34')](_0x0c82('0xf'),_0x23f783,_0x566e08[_0x0c82('0x2a')]);_0x32e9ee[_0x0c82('0x32')]();});}}catch(_0xd20af1){logger[_0x0c82('0x34')](_0x0c82('0xf'),_0x23f783,JSON[_0x0c82('0x33')](_0xd20af1));_0x32e9ee[_0x0c82('0x27')]();}};};