c0c807c4c8bcce249807371f7419deb85ae7803d
[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 _0xf603=['YYYY-MM-DD\x20HH:mm:ss','channel','whatsapp','phone','chat','ChatWebsiteId','upperFirst','account','created','isEmpty','body','getMustacheRender','Message','create','then','catch','error','stringify','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','providerName','providerResponse','metadata','endConversation','lodash','moment','md5','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','isNil','interaction','UserId','info','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format'];(function(_0x2f63de,_0x11935c){var _0x4acf4b=function(_0x1ac0e4){while(--_0x1ac0e4){_0x2f63de['push'](_0x2f63de['shift']());}};_0x4acf4b(++_0x11935c);}(_0xf603,0x124));var _0x3f60=function(_0x140637,_0x2d3bfe){_0x140637=_0x140637-0x0;var _0x2607ef=_0xf603[_0x140637];return _0x2607ef;};'use strict';var _=require(_0x3f60('0x0'));var moment=require(_0x3f60('0x1'));var apiai=require('apiai-promise');var md5=require(_0x3f60('0x2'));var utils=require(_0x3f60('0x3'));var logger=require(_0x3f60('0x4'))(_0x3f60('0x5'));var rpc={'chatMessage':require(_0x3f60('0x6')),'openchannelMessage':require(_0x3f60('0x7')),'mailMessage':require(_0x3f60('0x8')),'smsMessage':require(_0x3f60('0x9')),'faxMessage':require(_0x3f60('0xa')),'whatsappMessage':require('../../rpc/whatsappMessage')};exports['consequence']=function(_0x49a08c,_0x413b11){return function(_0x43ec55){try{if(!_[_0x3f60('0xb')](this[_0x3f60('0xc')][_0x3f60('0xd')])){logger[_0x3f60('0xe')](_0x3f60('0xf'),_0x49a08c,_0x3f60('0x10'));return _0x43ec55[_0x3f60('0x11')]();}var _0xbeb1f3={'ContactId':this[_0x3f60('0x12')]['id'],'sentAt':moment()[_0x3f60('0x13')](_0x3f60('0x14')),'direction':'out'};if(this['channel']==='sms'||this[_0x3f60('0x15')]===_0x3f60('0x16')){_0xbeb1f3[_0x3f60('0x17')]=this['interaction'][_0x3f60('0x17')];}var _0x64976a=this['channel'];if(_0x64976a===_0x3f60('0x18')){_0xbeb1f3[_0x3f60('0x19')]=this['account']['id'];}else{_0xbeb1f3[_[_0x3f60('0x1a')](_0x64976a)+'AccountId']=this[_0x3f60('0x1b')]['id'];}_0xbeb1f3[_[_0x3f60('0x1a')](_0x64976a)+'InteractionId']=this[_0x3f60('0xc')]['id'];if(this['interaction'][_0x3f60('0x1c')]){var _0x4fe8ee=_0x413b11[0x2];if(!_[_0x3f60('0x1d')](_0x4fe8ee)){_0xbeb1f3[_0x3f60('0x1e')]=utils[_0x3f60('0x1f')](_0x4fe8ee,this);return rpc[_0x64976a+_0x3f60('0x20')][_0x3f60('0x21')](_0xbeb1f3)[_0x3f60('0x22')](function(_0x52aa44){logger[_0x3f60('0xe')](_0x3f60('0xf'),_0x49a08c,_0xbeb1f3[_0x3f60('0x1e')]);})[_0x3f60('0x23')](function(_0x167372){logger[_0x3f60('0x24')]('[%s][DIALOGFLOW]\x20%s',_0x49a08c,JSON[_0x3f60('0x25')](_0x167372));})[_0x3f60('0x26')](function(){logger['info'](_0x3f60('0x27'),_0x49a08c);_0x43ec55[_0x3f60('0x28')]();});}else{logger[_0x3f60('0xe')](_0x3f60('0x29'),_0x49a08c);_0x43ec55[_0x3f60('0x28')]();}}else{var _0x1b161e=this;var _0x44b665=apiai(_0x413b11[0x0],{'language':_0x413b11[0x1]||'en'});return _0x44b665[_0x3f60('0x2a')](this[_0x3f60('0x2b')][_0x3f60('0x1e')],{'sessionId':md5(this[_0x3f60('0xc')]['id'])})[_0x3f60('0x22')](function(_0x1f9390){_0x1b161e[_0x3f60('0x1e')][_0x3f60('0x2c')]=_0x1f9390;_0xbeb1f3['body']=_0x1f9390[_0x3f60('0x2d')][_0x3f60('0x2e')][_0x3f60('0x2f')];_0xbeb1f3[_0x3f60('0x30')]=_0x3f60('0x2c');_0xbeb1f3[_0x3f60('0x31')]=JSON[_0x3f60('0x25')](_0x1f9390);return rpc[_0x64976a+_0x3f60('0x20')]['create'](_0xbeb1f3)[_0x3f60('0x22')](function(_0x1829f2){logger[_0x3f60('0xe')](_0x3f60('0xf'),_0x49a08c,_0xbeb1f3[_0x3f60('0x1e')]);if(_0x1f9390[_0x3f60('0x2d')][_0x3f60('0x32')][_0x3f60('0x33')]){_0x43ec55[_0x3f60('0x11')]();}else{_0x43ec55[_0x3f60('0x28')]();}})[_0x3f60('0x23')](function(_0x457e5b){logger[_0x3f60('0x24')](_0x3f60('0xf'),_0x49a08c,JSON[_0x3f60('0x25')](_0x457e5b));_0x43ec55[_0x3f60('0x11')]();});})[_0x3f60('0x23')](function(_0x3dd647){logger[_0x3f60('0x24')](_0x3f60('0xf'),_0x49a08c,_0x3dd647[_0x3f60('0x2b')]);_0x43ec55[_0x3f60('0x11')]();});}}catch(_0x190306){logger[_0x3f60('0x24')](_0x3f60('0xf'),_0x49a08c,JSON[_0x3f60('0x25')](_0x190306));_0x43ec55[_0x3f60('0x28')]();}};};