Skip to content

Commit

Permalink
Updated to leave the session open by default. Also added capability t…
Browse files Browse the repository at this point in the history
…o specifically close a conversation using an InputHint.
  • Loading branch information
garypretty committed Feb 15, 2018
1 parent 673fca3 commit d3b1049
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ actionsOnGoogleAdapter.onUserSignedInHandlerProvider.registerHandler((user) => {

### Controlling the session (should we wait for another message from the user?)

This bridge supports InputHint properties on Bot Framework activities when using the SayAsync method (as opposed to PostAsync), which determine if the bot should wait for further input from the user in a voice scenario.
By default this bridge will leave the session open after returning a response to Google and will expect further input from the user, which will allow them to continue their conversation with your action. If you wish to end the session by default following each message, there an environment setting 'DEFAULT_LEAVE_SESSION_OPEN' which you can set to "false" to achieve this.

The bridge looks for an inputHint on the incoming activity from the bot, specifically looking for the 'expectingInput' hint, which will cause the bridge to leave the conversation open and allow the user to say something else without explicitly invoking the skill again.
This bridge also supports InputHint properties on Bot Framework activities when using the SayAsync method (as opposed to PostAsync), which determine if the bot should wait for further input from the user in a voice scenario.

Below is an example of using the above features in a C# bot. In this example we send a message from the bot to the bridge and also indicate that we are expecting an answer from the user.
The bridge looks for an inputHint on the incoming activity from the bot, specifically looking for either the 'ExpectingInput' hint, which will cause the bridge to leave the conversation open, or 'IgnoringInput', which will end the conversation. So, for example, if you have sessions being left open by default you could use the 'IgnoringInput' InputHint to end the session. Conversely, if you end the session by default, you can send the 'ExpectingInput' InputHint on your bot activity to indicate that we should wait for the user to say something else.

Below is an example of using the above InputHint features in a C# bot. In this example we send a message from the bot to the bridge and also indicate that we are expecting a further message from the user.

```cs
var messageText = "Thanks! Can I help you with something else?";
Expand All @@ -120,8 +122,6 @@ var messageOptions = new MessageOptions
await context.SayAsync(messageText, speakText, options: messageOptions);
```

By default, if the inputHint for 'expectingInput' is not found, the session will close (i.e. the app.tell method is used when returning a response via the Google Actions SDK), whereas if it is found then the app.ask method is used. If you wish to leave the session open by default, there an environment setting 'DEFAULT_LEAVE_SESSION_OPEN' which, if set to "true", will leave the session open and accept more input by default without needing to specify it explicitly using the inputHint.

### Audio Cards

This bridge supports Microsoft Bot Framework Audio Cards:
Expand Down
19 changes: 16 additions & 3 deletions lib/actions-on-google/model/Activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@ module.exports = class Activity {
const instructions = new Instructions();
instructions.appendText(this.activityData.text);

const leaveSessionOpen = (process.env.DEFAULT_LEAVE_SESSION_OPEN) ? (process.env.DEFAULT_LEAVE_SESSION_OPEN == 'true') : false;
instructions.mergeShouldEndSession(((this.activityData.inputHint) && (this.activityData.inputHint == 'expectingInput')) ? false : !leaveSessionOpen);
const defaultLeaveSessionOpen = (process.env.DEFAULT_LEAVE_SESSION_OPEN)
? (process.env.DEFAULT_LEAVE_SESSION_OPEN == 'true')
: true;

const expectingInput = ((this.activityData.inputHint) && (this.activityData.inputHint == 'expectingInput')) ? true : false;
const ignoringInput = ((this.activityData.inputHint) && (this.activityData.inputHint == 'ignoringInput')) ? true : false;

const shouldLeaveSessionOpen = defaultLeaveSessionOpen;

if(expectingInput) {
shouldLeaveSessionOpen = true;
} else if(ignoringInput) {
shouldLeaveSessionOpen = false;
}

instructions.mergeShouldEndSession(!shouldLeaveSessionOpen);

if (this.activityData.attachments && this.activityData.attachments.length > 0) {
return this.activityData.attachments.reduce((accumulatedInstructions, attachment) => {
Expand All @@ -23,5 +37,4 @@ module.exports = class Activity {
return instructions;
}
}

};

0 comments on commit d3b1049

Please sign in to comment.