Skip to content

Commit

Permalink
Merge 37b6f60 into 60e7b47
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Brown committed Sep 12, 2018
2 parents 60e7b47 + 37b6f60 commit a19e85a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 44 deletions.
4 changes: 2 additions & 2 deletions libraries/botbuilder-core/src/botState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface CachedBotState {
* server.post('/api/messages', (req, res) => {
* adapter.processActivity(req, res, async (context) => {
* // Track up time
* const state = botState.get(context);
* const state = await botState.get(context);
* if (!('startTime' in state)) { state.startTime = new Date().getTime() }
* state.upTime = new Date().getTime() - state.stateTime;
*
Expand Down Expand Up @@ -176,7 +176,7 @@ export class BotState implements PropertyManager, Middleware {
* This example shows how to synchronously get an already loaded and cached state object:
*
* ```JavaScript
* const state botState.get(context);
* const state = await botState.get(context);
* ```
* @param context Context for current turn of conversation with the user.
*/
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder-core/src/botStateSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { TurnContext } from './turnContext';
* server.post('/api/messages', (req, res) => {
* adapter.processActivity(req, res, async (context) => {
* // Get state
* const convo = conversationState.get(context);
* const user = userState.get(context);
* const convo = await conversationState.get(context);
* const user = await userState.get(context);
*
* // ... route activity ...
*
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-core/src/conversationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const NO_KEY: string = `ConversationState: channelId and/or conversation missing
* server.post('/api/messages', (req, res) => {
* adapter.processActivity(req, res, async (context) => {
* // Get loaded conversation state
* const convo = conversationState.get(context);
* const convo = await conversationState.get(context);
*
* // ... route activity ...
*
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-core/src/userState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const NO_KEY: string = `UserState: channelId and/or conversation missing from co
* server.post('/api/messages', (req, res) => {
* adapter.processActivity(req, res, async (context) => {
* // Get loaded user state
* const user = userState.get(context);
* const user = await userState.get(context);
*
* // ... route activity ...
*
Expand Down
3 changes: 1 addition & 2 deletions libraries/botbuilder-dialogs/src/dialogContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export interface DialogState
* through to all of the bots dialogs and waterfall steps.
*
* ```JavaScript
* const conversation = conversationState.get(context);
* const dc = dialogs.createContext(context, conversation);
* const dc = await dialogs.createContext(context);
* ```
*/
export class DialogContext {
Expand Down
67 changes: 34 additions & 33 deletions libraries/botbuilder-dialogs/src/dialogSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,37 @@ import { DialogContext, DialogState } from './dialogContext';
* for their name and phone number:
*
* ```JavaScript
* const { DialogSet, TextPrompt } = require('botbuilder-dialogs');
* const { DialogSet, TextPrompt, WaterfallDialog, UserState, MemoryStorage } = require('botbuilder-dialogs');
*
* const memoryStorage = new MemoryStorage();
* const userState = new UserState(memoryStorage);
* const dialogs = new DialogSet();
*
* dialogs.add('fillProfile', [
* async function (dc, options) {
* dc.activeDialog.state.profile = {};
* await dc.prompt('textPrompt', `What's your name?`);
* const userProfile = userState.createProperty('profile');
*
* dialogs.add(new WaterfallDialog('fillProfile', [
* async (step) => {
* step.values.profile = {};
* return await step.prompt('textPrompt', `What's your name?`);
* },
* async function (dc, name) {
* dc.activeDialog.state.profile.name = name;
* await dc.prompt('textPrompt', `What's your phone number?`);
* async (step) => {
* step.values.profile.name = step.result;
* return await step.prompt('textPrompt', `What's your phone number?`);
* },
* async function (dc, phone) {
* dc.activeDialog.state.profile.phone = phone;
* async (step) => {
* step.values.profile.phone = step.result;
*
* // Save completed profile to user state
* const user = userState.get(context);
* user.profile = dc.activeDialog.state.profile;
* const user = await userProfile.get(step.context);
* user.profile = step.values.profile;
* await userProfile.set(step.context, user);
*
* // Notify user and end
* await dc.context.sendActivity(`Your profile was updated.`);
* await dc.end();
* await step.context.sendActivity(`Your profile was updated.`);
* return await step.end();
* }
* ]);
* ]));
*
* dialogs.add('textPrompt', new TextPrompt());
* dialogs.add(new TextPrompt('textPrompt'));
* ```
*
* At first glance it probably looks like we're making this simple task of asking the user two
Expand All @@ -74,11 +78,11 @@ import { DialogContext, DialogState } from './dialogContext';
* server.post('/api/messages', (req, res) => {
* adapter.processActivity(req, res, async (context) => {
* // Get conversation state and create DialogContext object
* const conversation = conversationState.get(context);
* const dc = dialogs.createContext(context, conversation);
* const dc = await dialogs.createContext(context);
*
* // Continue execution if there's an "active" dialog
* await dc.continue();
*
* if (!context.responded && context.activity.type === ActivityType.Message) {
* // No active dialogs so start 'fillProfile' dialog
* await dc.begin('fillProfile');
Expand Down Expand Up @@ -115,32 +119,30 @@ import { DialogContext, DialogState } from './dialogContext';
* server.post('/api/messages', (req, res) => {
* adapter.processActivity(req, res, async (context) => {
* // Get conversation state and create DialogContext object
* const conversation = conversationState.get(context);
* const dc = dialogs.createContext(context, conversation);
* const dc = await dialogs.createContext(context);
*
* // Check for any interruptions
* const isMessage = context.activity.type === ActivityType.Message;
* if (isMessage) {
* const utterance = context.activity.text.trim().toLowerCase();
* if (utterance.startsWith('edit profile')) {
* await dc.endAll().begin('fillProfile');
* return;
* return await dc.cancelAll().begin('fillProfile');
* } else if (utterance.startsWith('cancel')) {
* if (dc.activeDialog) {
* dc.endAll();
* await context.sendActivity(`Task canceled`);
* await dc.cancelAll();
* return await context.sendActivity(`Task canceled`);
* } else {
* await context.sendActivity(`Nothing to cancel`);
* return await context.sendActivity(`Nothing to cancel`);
* }
* return;
* }
* }
*
* // Continue execution if there's an "active" dialog
* await dc.continue();
*
* if (!context.responded && isMessage) {
* // Greet user and fill in profile if missing
* const user = userState.get(context);
* const user = await userState.get(context);
* if (!user.profile) {
* await context.sendActivity(`Hello... Lets fill out your profile to get started.`);
* await dc.begin('fillProfile');
Expand Down Expand Up @@ -173,9 +175,9 @@ export class DialogSet {
*
* ```JavaScript
* dialogs.add(new Waterfall('greeting', [
* async function (dc) {
* await dc.context.sendActivity(`Hello world!`);
* await dc.end();
* async function (step) {
* await step.context.sendActivity(`Hello world!`);
* await step.end();
* }
* ]));
* ```
Expand Down Expand Up @@ -203,8 +205,7 @@ export class DialogSet {
* that state.
*
* ```JavaScript
* const conversation = conversationState.get(context);
* const dc = dialogs.createContext(context, conversation);
* const dc = await dialogs.createContext(context);
* ```
* @param context Context for the current turn of conversation with the user.
*/
Expand Down
5 changes: 2 additions & 3 deletions libraries/botbuilder-dialogs/src/waterfallDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import { WaterfallStepContext } from './waterfallStepContext';
* @remarks
*
* ```TypeScript
* type WaterfallStep = (dc: DialogContext, args?: any, next?: SkipStepFunction) => Promise<DialogTurnResult>;
* type WaterfallStep = (step: WaterfallStepContext<O>) => Promise<DialogTurnResult>;
* ```
* @param WaterfallStep.context The dialog context for the current turn of conversation.
* @param WaterfallStep.step Contextual information for the current step being executed.
* @param WaterfallStepContext Contextual information for the current step being executed.
*/
export type WaterfallStep<O extends object = {}> = (step: WaterfallStepContext<O>) => Promise<DialogTurnResult>;

Expand Down

0 comments on commit a19e85a

Please sign in to comment.