metadata: platformVersion: "1.1" main: true name: WineryChats context: variables: iResult: "nlpresult" rb: "resourcebundle" orderSizes: "list.orderSizes" wineTypes: "list.wineTypes" redWines: "list.redWines" redWineCard: "map" whiteWines: "list.whiteWines" whiteWineCard: "map" chatType: "string" yesNo: "YES_NO" selectedWine: "string" defaultTransitions: actions: system.outOfOrderMessage: "outOfOrderMessageHandler" states: buildRedWineMenu: component: "System.SetVariable" properties: variable: "redWineCard" value: Cabernet Sauvignon: title: "Cabernet Sauvignon" description: "Flavor ot dark fruits like black cherry and blackberry along with a warm spice, vanilla and black pepper" image: "https://cdn.pixabay.com/photo/2016/05/24/16/16/wine-1412603__340.jpg" price: 35 Merlot: title: "Merlot" description: "With black cherry flavors, supple tannins, and chocolatey finish" image: "https://cdn.pixabay.com/photo/2016/05/24/16/19/wine-1412606__340.jpg" price: 25 Pinot noir: title: "Pinot noir" description: "Complex flavor that includes cherry, raspberry, mushroom and forest floor" image: "https://cdn.pixabay.com/photo/2014/09/22/16/17/red-wine-456434__340.jpg" price: 12 Zinfandel: title: "Zinfandel" description: "Jam, blueberry, black pepper, cherry, plum and cranberry flavored wine" image: "https://cdn.pixabay.com/photo/2017/08/17/22/55/red-2653222__340.jpg" price: 18 transitions: next: "buildWhiteWineMenu" buildWhiteWineMenu: component: "System.SetVariable" properties: variable: "whiteWineCard" value: Chardonnay: title: "Chardonnay" description: "A yummy buttery aroma and flavor with an oaky smell." image: "https://cdn.pixabay.com/photo/2018/02/27/14/07/white-wine-3185546__340.jpg" price: 28 Sauvignon blanc: title: "Sauvignon blanc" description: "A broad spectrum of flavor ranging from mineral-driven and flinty to grassy and tropical fruits." image: "https://cdn.pixabay.com/photo/2018/06/22/09/18/cheese-and-wine-3490303__340.jpg" price: 31 Riesling: title: "Riesling" description: "A versatile German wine with a refreshing nature. Very crisp" image: "https://cdn.pixabay.com/photo/2019/12/01/18/02/vineyards-4666055__340.jpg" price: 17 Pinot grigio: title: "Pinot grigio" description: "A flavor that contains notes of pineapple and peach, pear and mineral undertones" image: "https://pixabay.com/photos/white-wine-alcohol-2653226/" price: 22 transitions: next: "welcome" welcome: component: "System.Output" properties: text: "Welcome to 'Winery Chats'. I'm 'Grapy', a chatbot with which you can order the best wines in the world or get your wine-specific questions answered. So, let me help you too." keepTurn: true transitions: next: "getIntent" getIntent: component: "System.Intent" properties: variable: "iResult" daIntercept: "always" transitions: actions: tellme.about.wine: "setChatToExplainType" order.wine: "setChatToOrderType" unresolvedIntent: "handleBotNotUnderstanding" setChatToOrderType: component: "System.SetVariable" properties: variable: "chatType" value: "order" transitions: next: "startDetermineWineType" startDetermineWineType: component: "System.Switch" properties: source: "${iResult.value.entityMatches['list.redWines']?has_content?then('redWine',iResult.value.entityMatches['list.whiteWines']?has_content?then('whiteWine', 'none'))}" values: - "redWine" - "whiteWine" transitions: actions: redWine: "selectRedWine" whiteWine: "selectWhiteWine" NONE: "checkForWineColor" selectRedWine: component: "System.CommonResponse" properties: processUserMessage: true variable: "redWines" nlpResultVariable: "iResult" useFullEntityMatches: false maxPrompts: 2 metadata: responseItems: - type: "text" text: "${system.entityToResolve.value.prompt}" footerText: visible: expression: entitiesToResolve: include: exclude: channels: include: exclude: onInvalidUserInput: actions: - label: "${(enumValue?index?number +1)?lower_abc}. ${enumValue}" type: "postback" iteratorVariable: "system.entityToResolve.value.enumValues" keyword: "${(enumValue?index?number +1)?lower_abc}, ${enumValue}" payload: variables: redWines: "${enumValue}" visible: globalActions: - label: "Show Previous" type: "postback" visible: expression: "${system.entityToResolve.value.needShowPreviousButton}" payload: action: "system.showPrevious" variables: ${system.entityToResolve.value.rangeStartVar}: ${system.entityToResolve.value.previousRangeStart} - label: "Show More" type: "postback" visible: expression: "${system.entityToResolve.value.needShowMoreButton}" payload: action: "system.showMore" variables: ${system.entityToResolve.value.rangeStartVar}: ${system.entityToResolve.value.nextRangeStart} - label: "Cancel" type: "postback" visible: onInvalidUserInput: true payload: action: "cancel" transitions: next: "saveSelectedWine" actions: cancel: "cancelOrder" selectWhiteWine: component: "System.CommonResponse" properties: processUserMessage: true variable: "whiteWines" nlpResultVariable: "iResult" useFullEntityMatches: false maxPrompts: 2 metadata: responseItems: - type: "text" text: "${system.entityToResolve.value.prompt}" footerText: visible: expression: entitiesToResolve: include: exclude: channels: include: exclude: onInvalidUserInput: actions: - label: "${(enumValue?index?number +1)?lower_abc}. ${enumValue}" type: "postback" iteratorVariable: "system.entityToResolve.value.enumValues" keyword: "${(enumValue?index?number +1)?lower_abc}, ${enumValue}" payload: variables: whiteWines: "${enumValue}" visible: globalActions: - label: "Show Previous" type: "postback" visible: expression: "${system.entityToResolve.value.needShowPreviousButton}" payload: action: "system.showPrevious" variables: ${system.entityToResolve.value.rangeStartVar}: ${system.entityToResolve.value.previousRangeStart} - label: "Show More" type: "postback" visible: expression: "${system.entityToResolve.value.needShowMoreButton}" payload: action: "system.showMore" variables: ${system.entityToResolve.value.rangeStartVar}: ${system.entityToResolve.value.nextRangeStart} - label: "Cancel" type: "postback" visible: onInvalidUserInput: true payload: action: "cancel" transitions: next: "saveSelectedWine" actions: cancel: "cancelOrder" checkForWineColor: component: "System.CommonResponse" properties: processUserMessage: true variable: "wineTypes" nlpResultVariable: "iResult" useFullEntityMatches: false maxPrompts: 2 metadata: responseItems: - type: "text" text: "${system.entityToResolve.value.prompt}" footerText: visible: expression: entitiesToResolve: include: exclude: channels: include: exclude: onInvalidUserInput: actions: - label: "${enumValue}" type: "postback" iteratorVariable: "system.entityToResolve.value.enumValues" keyword: payload: variables: wineTypes: "${enumValue}" visible: globalActions: - label: "Show Previous" type: "postback" visible: expression: "${system.entityToResolve.value.needShowPreviousButton}" payload: action: "system.showPrevious" variables: ${system.entityToResolve.value.rangeStartVar}: ${system.entityToResolve.value.previousRangeStart} - label: "Show More" type: "postback" visible: expression: "${system.entityToResolve.value.needShowMoreButton}" payload: action: "system.showMore" variables: ${system.entityToResolve.value.rangeStartVar}: ${system.entityToResolve.value.nextRangeStart} - label: "Cancel" type: "postback" visible: onInvalidUserInput: true payload: action: "cancel" transitions: next: "determineWineMenu" actions: cancel: "cancelOrder" determineWineMenu: component: "System.Switch" properties: variable: "wineTypes" values: - "red wine" - "white wine" transitions: actions: red wine: "selectRedWine" white wine: "selectWhiteWine" NONE: "checkForWineColor" saveSelectedWine: component: "System.SetVariable" properties: variable: "selectedWine" value: "${redWines.value?hasContent?then(redWines.value, whiteWines.value)}" transitions: next: "branchToOrderOrQuestionFlow" branchToOrderOrQuestionFlow: component: "System.ConditionEquals" properties: variable: "chatType" source: value: "order" transitions: actions: equal: "askShippingSize" notequal: "showAnswerToQuestion" askShippingSize: component: "System.ResolveEntities" properties: variable: "orderSizes" useFullEntityMatches: false maxPrompts: 2 showMoreLabel: showPreviousLabel: transitions: next: "summarizeOrder" actions: cancel: "askCancelOrder" askCancelOrder: component: "System.CommonResponse" properties: processUserMessage: true variable: "yesNo" useFullEntityMatches: false maxPrompts: 2 metadata: responseItems: - type: "text" text: "I cannot ship wine without an order Size. Do you want to cancel this order (yes/no)?" footerText: transitions: actions: match: "checkCancelOrderOrNot" cancel: "cancelOrder" checkCancelOrderOrNot: component: "System.ConditionEquals" properties: source: "${yesNo.value.yesno}" value: "YES" transitions: actions: equal: "cancelOrder" notequal: "askShippingSize" cancelOrder: component: "System.Output" properties: text: "Our winery chat just ended here. If you wish, we can start over again. If not, then have a good day, cheers - your friend Grapy" keepTurn: false transitions: return: "done" summarizeOrder: component: "System.CommonResponse" properties: processUserMessage: false keepTurn: false metadata: responseItems: - type: "attachment" headerText: "Order Summary" attachmentType: "image" attachmentUrl: "${redWineCard.value[selectedWine]?has_content?then(redWineCard.value[selectedWine].image, whiteWineCard.value[selectedWine].image)}" footerText: "You ordered ${orderSizes.value} of ${selectedWine.value} for ${redWineCard.value[selectedWine]?has_content?then(redWineCard.value[selectedWine].price, whiteWineCard.value[selectedWine].price)}$ per bottle." transitions: return: "done" setChatToExplainType: component: "System.SetVariable" properties: variable: "chatType" value: "question" transitions: next: "confirmQuestion" confirmQuestion: component: "System.Output" properties: text: "Let me get your question answered." keepTurn: true transitions: next: "startDetermineWineType" showAnswerToQuestion: component: "System.Output" properties: text: "${rb(selectedWine.value)}" keepTurn: true transitions: next: "goodbye" goodbye: component: "System.Output" properties: text: "Hope I could help. If you want, ask another question." keepTurn: false transitions: return: "done" handleBotNotUnderstanding: component: "System.Output" properties: text: "Hmm, seems I did not quite understand. I hope my wine skills are better. You can try my wine skills by sending a message like 'I want to order wine'" keepTurn: false transitions: return: "done" outOfOrderMessageHandler: component: "System.ConditionEquals" properties: variable: source: "${(system.expectedState == 'buildRedWineMenu')?then('disAllowNavigation','allowNavigation')}" value: "allowNavigation" transitions: actions: equal: "${system.actualState}" notequal: "navigationNotAllowedMessage" navigationNotAllowedMessage: component: "System.Output" properties: text: "I can't change the direction at this point in the conversation. Please start a new chat for any new orders or questions you have." keepTurn: false transitions: return: "done"