bde9a87e1c595e517b04e00b25b1cfd95ffa7f8c
[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 _0xab8f=['../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','phone','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','created','isEmpty','getMustacheRender','Message','then','info','[%s][DIALOGFLOW]\x20%s','stringify','finally','stop','textRequest','message','body','dialogflow','fulfillment','speech','providerName','providerResponse','create','metadata','endConversation','catch','error','next','lodash','moment','apiai-promise','md5','./utils','../../../../config/logger','routing'];(function(_0x45bf86,_0x75586e){var _0x1f02b7=function(_0x1ea8a3){while(--_0x1ea8a3){_0x45bf86['push'](_0x45bf86['shift']());}};_0x1f02b7(++_0x75586e);}(_0xab8f,0x12b));var _0xfab8=function(_0x2b8041,_0x43be76){_0x2b8041=_0x2b8041-0x0;var _0x10c418=_0xab8f[_0x2b8041];return _0x10c418;};'use strict';var _=require(_0xfab8('0x0'));var moment=require(_0xfab8('0x1'));var apiai=require(_0xfab8('0x2'));var md5=require(_0xfab8('0x3'));var utils=require(_0xfab8('0x4'));var logger=require(_0xfab8('0x5'))(_0xfab8('0x6'));var rpc={'chatMessage':require(_0xfab8('0x7')),'openchannelMessage':require(_0xfab8('0x8')),'mailMessage':require(_0xfab8('0x9')),'smsMessage':require(_0xfab8('0xa')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0xfab8('0xb'))};exports[_0xfab8('0xc')]=function(_0x2ca3c7,_0x2da4ab){return function(_0x378fb6){try{if(!_[_0xfab8('0xd')](this[_0xfab8('0xe')]['UserId'])){logger['info']('[%s][DIALOGFLOW]\x20%s',_0x2ca3c7,_0xfab8('0xf'));return _0x378fb6['next']();}var _0xbfe125={'ContactId':this[_0xfab8('0x10')]['id'],'sentAt':moment()['format'](_0xfab8('0x11')),'direction':_0xfab8('0x12')};if(this[_0xfab8('0x13')]===_0xfab8('0x14')||this[_0xfab8('0x13')]==='whatsapp'){_0xbfe125[_0xfab8('0x15')]=this['interaction'][_0xfab8('0x15')];}var _0x3c5268=this[_0xfab8('0x13')];if(_0x3c5268==='chat'){_0xbfe125[_0xfab8('0x16')]=this[_0xfab8('0x17')]['id'];}else{_0xbfe125[_[_0xfab8('0x18')](_0x3c5268)+_0xfab8('0x19')]=this[_0xfab8('0x17')]['id'];}_0xbfe125[_[_0xfab8('0x18')](_0x3c5268)+_0xfab8('0x1a')]=this[_0xfab8('0xe')]['id'];if(this[_0xfab8('0xe')][_0xfab8('0x1b')]){var _0x2f87d4=_0x2da4ab[0x2];if(!_[_0xfab8('0x1c')](_0x2f87d4)){_0xbfe125['body']=utils[_0xfab8('0x1d')](_0x2f87d4,this);return rpc[_0x3c5268+_0xfab8('0x1e')]['create'](_0xbfe125)[_0xfab8('0x1f')](function(_0x5f4411){logger[_0xfab8('0x20')](_0xfab8('0x21'),_0x2ca3c7,_0xbfe125['body']);})['catch'](function(_0x1b1460){logger['error'](_0xfab8('0x21'),_0x2ca3c7,JSON[_0xfab8('0x22')](_0x1b1460));})[_0xfab8('0x23')](function(){logger['info']('[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x2ca3c7);_0x378fb6['stop']();});}else{logger['info']('[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x2ca3c7);_0x378fb6[_0xfab8('0x24')]();}}else{var _0x4792f4=this;var _0x1a28b8=apiai(_0x2da4ab[0x0],{'language':_0x2da4ab[0x1]||'en'});return _0x1a28b8[_0xfab8('0x25')](this[_0xfab8('0x26')][_0xfab8('0x27')],{'sessionId':md5(this['interaction']['id'])})[_0xfab8('0x1f')](function(_0x4ff9ad){_0x4792f4['body'][_0xfab8('0x28')]=_0x4ff9ad;_0xbfe125['body']=_0x4ff9ad['result'][_0xfab8('0x29')][_0xfab8('0x2a')];_0xbfe125[_0xfab8('0x2b')]=_0xfab8('0x28');_0xbfe125[_0xfab8('0x2c')]=JSON['stringify'](_0x4ff9ad);return rpc[_0x3c5268+_0xfab8('0x1e')][_0xfab8('0x2d')](_0xbfe125)['then'](function(_0x3f2aaa){logger[_0xfab8('0x20')](_0xfab8('0x21'),_0x2ca3c7,_0xbfe125[_0xfab8('0x27')]);if(_0x4ff9ad['result'][_0xfab8('0x2e')][_0xfab8('0x2f')]){_0x378fb6['next']();}else{_0x378fb6['stop']();}})[_0xfab8('0x30')](function(_0xdfd783){logger[_0xfab8('0x31')](_0xfab8('0x21'),_0x2ca3c7,JSON[_0xfab8('0x22')](_0xdfd783));_0x378fb6[_0xfab8('0x32')]();});})[_0xfab8('0x30')](function(_0x4443ca){logger['error']('[%s][DIALOGFLOW]\x20%s',_0x2ca3c7,_0x4443ca[_0xfab8('0x26')]);_0x378fb6[_0xfab8('0x32')]();});}}catch(_0x169fed){logger[_0xfab8('0x31')]('[%s][DIALOGFLOW]\x20%s',_0x2ca3c7,JSON['stringify'](_0x169fed));_0x378fb6[_0xfab8('0x24')]();}};};