-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13ac711
commit c40fb69
Showing
2 changed files
with
140 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
// INK script to test long term session attribute functions | ||
|
||
-> start | ||
|
||
// holds the order number for the current conversation | ||
VAR order_number = "" | ||
|
||
=== start === | ||
+ CreateOrderIntent -> create_order | ||
+ CheckStatusIntent -> check_status | ||
-> END | ||
|
||
=== create_order === | ||
~ order_number = 123456 // fake order creation | ||
Your order {order_number} has been created! | ||
::SET_LONG_TERM_ATTR name::currentorder value::{order_number} | ||
-> END | ||
|
||
=== check_status === | ||
::GET_LONG_TERM_ATTR name::currentorder var::order_number | ||
{ | ||
- order_number == "": | ||
-> get_order_number_for_status_check | ||
- else: | ||
-> check_order_status | ||
} | ||
-> END | ||
|
||
= get_order_number_for_status_check | ||
What is the order number of the order you want to check the status of ? | ||
// the rest of this divert would: | ||
// * capture the order number via a number intent | ||
// * set the order_number variable | ||
// * jump to display_order_status | ||
-> END | ||
|
||
= check_order_status | ||
For order {order_number} ? | ||
::SET_REPROMPT For order {order_number} ? Please answer Yes or No. | ||
::SET_HINT Yes or No | ||
::ADD_QUICK_REPLY Yes | ||
::ADD_QUICK_REPLY No | ||
+ YesIntent | ||
-> display_order_details | ||
+ NoIntent | ||
// customer wants to talk about another order so unset current order long term attribute | ||
::REMOVE_LONG_TERM_ATTR name::currentorder | ||
-> get_order_number_for_status_check | ||
-> END | ||
|
||
= display_order_details | ||
// return dummy status | ||
Order {order_number} is currently being packed. | ||
// store current order for next conversation in session | ||
::SET_LONG_TERM_ATTR name::currentorder value::{order_number} | ||
// INK script to test long term session attribute functions | ||
|
||
-> start | ||
|
||
// holds the order number for the current conversation | ||
VAR order_number = "" | ||
|
||
=== start === | ||
+ CreateOrderIntent -> create_order | ||
+ CheckStatusIntent -> check_status | ||
-> END | ||
|
||
=== create_order === | ||
~ order_number = 123456 // fake order creation | ||
Your order {order_number} has been created! | ||
::SET_LONG_TERM_ATTR name::currentorder value::{order_number} | ||
-> END | ||
|
||
=== check_status === | ||
::GET_LONG_TERM_ATTR name::currentorder var::order_number | ||
{ | ||
- order_number == "": | ||
-> get_order_number_for_status_check | ||
- else: | ||
-> check_order_status | ||
} | ||
-> END | ||
|
||
= get_order_number_for_status_check | ||
What is the order number of the order you want to check the status of ? | ||
// the rest of this divert would: | ||
// * capture the order number via a number intent | ||
// * set the order_number variable | ||
// * jump to display_order_status | ||
-> END | ||
|
||
= check_order_status | ||
For order {order_number} ? | ||
::SET_REPROMPT For order {order_number} ? Please answer Yes or No. | ||
::SET_HINT Yes or No | ||
::ADD_QUICK_REPLY Yes | ||
::ADD_QUICK_REPLY No | ||
+ YesIntent | ||
-> display_order_details | ||
+ NoIntent | ||
// customer wants to talk about another order so unset current order long term attribute | ||
::REMOVE_LONG_TERM_ATTR name::currentorder | ||
-> get_order_number_for_status_check | ||
-> END | ||
|
||
= display_order_details | ||
// return dummy status | ||
Order {order_number} is currently being packed. | ||
// store current order for next conversation in session | ||
::SET_LONG_TERM_ATTR name::currentorder value::{order_number} | ||
-> END |
170 changes: 85 additions & 85 deletions
170
...test/java/com/rabidgremlin/mutters/bot/ink/functions/TestRepromptQuickRepliesAndHint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,85 @@ | ||
package com.rabidgremlin.mutters.bot.ink.functions; | ||
|
||
import com.rabidgremlin.mutters.bot.ink.functions.orderbot.OrderInkBot; | ||
import com.rabidgremlin.mutters.bot.ink.functions.orderbot.OrderInkBotConfiguration; | ||
import com.rabidgremlin.mutters.core.Context; | ||
import com.rabidgremlin.mutters.core.bot.BotResponse; | ||
import com.rabidgremlin.mutters.core.session.Session; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.hasItems; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class TestRepromptQuickRepliesAndHint | ||
{ | ||
private static OrderInkBot orderBot = new OrderInkBot(new OrderInkBotConfiguration()); | ||
|
||
@Test | ||
public void givenFailedMatchShouldIncludeRepromptHintQuickRelies() throws Exception | ||
{ | ||
Session session = new Session(); | ||
Context context = new Context(); | ||
|
||
// do the order so value is set | ||
BotResponse response = orderBot.respond(session, context, "Order a widget"); | ||
|
||
// ask for status which should use long term current order as context | ||
response = orderBot.respond(session, context, "What is the status of my order"); | ||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ?")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
response = orderBot.respond(session, context, "Hmm..."); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ? Please answer Yes or No.")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
|
||
response = orderBot.respond(session, context, "What?"); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ? Please answer Yes or No.")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void givenFailedMatchShouldClearRepromptHintQuickReliesAfterSuccessfulMatch() throws Exception | ||
{ | ||
Session session = new Session(); | ||
Context context = new Context(); | ||
|
||
// do the order so value is set | ||
BotResponse response = orderBot.respond(session, context, "Order a widget"); | ||
|
||
// ask for status which should use long term current order as context | ||
response = orderBot.respond(session, context, "What is the status of my order"); | ||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ?")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
response = orderBot.respond(session, context, "Hmm..."); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ? Please answer Yes or No.")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
response = orderBot.respond(session, context, "No"); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("What is the order number of the order you want to check the status of ?")); | ||
assertThat(response.getHint(), is(nullValue())); | ||
assertThat(response.getQuickReplies(), is(nullValue())); | ||
} | ||
|
||
} | ||
package com.rabidgremlin.mutters.bot.ink.functions; | ||
|
||
import com.rabidgremlin.mutters.bot.ink.functions.orderbot.OrderInkBot; | ||
import com.rabidgremlin.mutters.bot.ink.functions.orderbot.OrderInkBotConfiguration; | ||
import com.rabidgremlin.mutters.core.Context; | ||
import com.rabidgremlin.mutters.core.bot.BotResponse; | ||
import com.rabidgremlin.mutters.core.session.Session; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.hasItems; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class TestRepromptQuickRepliesAndHint | ||
{ | ||
private static OrderInkBot orderBot = new OrderInkBot(new OrderInkBotConfiguration()); | ||
|
||
@Test | ||
public void givenFailedMatchShouldIncludeRepromptHintQuickRelies() throws Exception | ||
{ | ||
Session session = new Session(); | ||
Context context = new Context(); | ||
|
||
// do the order so value is set | ||
BotResponse response = orderBot.respond(session, context, "Order a widget"); | ||
|
||
// ask for status which should use long term current order as context | ||
response = orderBot.respond(session, context, "What is the status of my order"); | ||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ?")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
response = orderBot.respond(session, context, "Hmm..."); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ? Please answer Yes or No.")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
|
||
response = orderBot.respond(session, context, "What?"); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ? Please answer Yes or No.")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void givenFailedMatchShouldClearRepromptHintQuickReliesAfterSuccessfulMatch() throws Exception | ||
{ | ||
Session session = new Session(); | ||
Context context = new Context(); | ||
|
||
// do the order so value is set | ||
BotResponse response = orderBot.respond(session, context, "Order a widget"); | ||
|
||
// ask for status which should use long term current order as context | ||
response = orderBot.respond(session, context, "What is the status of my order"); | ||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ?")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
response = orderBot.respond(session, context, "Hmm..."); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("For order 123456 ? Please answer Yes or No.")); | ||
assertThat(response.getHint(), is("Yes or No")); | ||
assertThat(response.getQuickReplies(), hasItems("Yes", "No")); | ||
|
||
response = orderBot.respond(session, context, "No"); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getResponse(), is("What is the order number of the order you want to check the status of ?")); | ||
assertThat(response.getHint(), is(nullValue())); | ||
assertThat(response.getQuickReplies(), is(nullValue())); | ||
} | ||
|
||
} |