/// <summary> /// we call for every turn while the topic is still active /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task <bool> ContinueTopic(NumberBotContext context) { // for messages if (context.Activity.Type == ActivityTypes.Message) { switch (context.RecognizedIntents.TopIntent?.Name) { case "showGuesses": // allow show alarm to interrupt, but it's one turn, so we show the data without changing the topic await new ShowGamesTopic().StartTopic(context); return(await this.PromptForMissingData(context)); // Continue Topic - showGames case "help": // show contextual help await AddGameResponses.ReplyWithHelp(context, this.Game); return(await this.PromptForMissingData(context)); // Continue Topic - help case "cancel": // prompt to cancel await AddGameResponses.ReplyWithCancelPrompt(context, this.Game); this.TopicState = TopicStates.CancelConfirmation; // Continue Topic cancel return(true); default: return(await ProcessTopicState(context)); } } return(true); }
public async Task OnReceiveActivity(ITurnContext botContext) { // Get the current ActiveTopic from my persisted conversation state var context = new NumberBotContext(botContext); var handled = false; // if we don't have an active topic yet if (context.ConversationState.ActiveTopic == null) { // use the default topic context.ConversationState.ActiveTopic = new DefaultTopic(); handled = await context.ConversationState.ActiveTopic.StartTopic(context); } else { // we do have an active topic, so call it handled = await context.ConversationState.ActiveTopic.ContinueTopic(context); } // if activeTopic's result is false and the activeTopic is NOT already the default topic if (handled == false && !(context.ConversationState.ActiveTopic is DefaultTopic)) { // Use DefaultTopic as the active topic context.ConversationState.ActiveTopic = new DefaultTopic(); await context.ConversationState.ActiveTopic.ResumeTopic(context); } }
/// <summary> /// Method which is called when this topic is resumed after an interruption /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task <bool> ResumeTopic(NumberBotContext context) { // just prompt the user to ask what they want to do await DefaultResponses.ReplyWithResumeTopic(context); return(true); }
/// <summary> /// Called when topic is activated (SINGLE TURN) /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task <bool> StartTopic(NumberBotContext context) { await ShowGames(context); // end the topic immediately return(false); }
/// <summary> /// Called when the add game topic is started /// </summary> /// <param name="context"></param> /// <returns></returns> public Task <bool> StartTopic(NumberBotContext context) { this.Game = new Game(); this.Guess = new Guess(); //this.Game = new Game() //{ // // initialize from intent entities // Title = context.RecognizedIntents.TopIntent?.Entities.Where(entity => entity.GroupName == "1") // .Select(entity => entity.ValueAs<string>()).FirstOrDefault(), //}; return(PromptForMissingData(context)); // Start Topic return }
/// <summary> /// Continue the topic, method which is routed to while this topic is active /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task <bool> ContinueTopic(NumberBotContext context) { switch (context.Activity.Type) { case ActivityTypes.Message: switch (context.RecognizedIntents.TopIntent?.Name) { case "startGuess": // switch to startGame topic context.ConversationState.ActiveTopic = new StartGameTopic(); return(await context.ConversationState.ActiveTopic.StartTopic(context)); case "showGuesses": // switch to show games topic context.ConversationState.ActiveTopic = new ShowGamesTopic(); return(await context.ConversationState.ActiveTopic.StartTopic(context)); //case "deleteAlarm": // // switch to delete alarm topic // context.ConversationState.ActiveTopic = new DeleteAlarmTopic(); // return await context.ConversationState.ActiveTopic.StartTopic(context); case "help": // show help await DefaultResponses.ReplyWithHelp(context); return(true); default: // show our confusion await DefaultResponses.ReplyWithConfused(context); return(true); } default: break; } return(true); }
/// <summary> /// Called when the default topic is started /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task <bool> StartTopic(NumberBotContext context) { switch (context.Activity.Type) { case ActivityTypes.ConversationUpdate: { // greet when added to conversation var activity = context.Activity.AsConversationUpdateActivity(); if (activity.MembersAdded.Any(m => m.Id == activity.Recipient.Id)) { this.MinNumber = 1; this.MaxNumber = 100; Random rnd = new Random(); this.SecretNumber = rnd.Next(this.MinNumber, this.MaxNumber); context.UserState.SecretNumber = this.SecretNumber; await DefaultResponses.ReplyWithGreeting(context); await DefaultResponses.ReplyWithHelp(context); this.Greeted = true; } } break; case ActivityTypes.Message: // greet on first message if we haven't already if (!Greeted) { await DefaultResponses.ReplyWithGreeting(context); this.Greeted = true; } return(await this.ContinueTopic(context)); } return(true); }
/// <summary> /// Called when this topic is resumed after being interrupted /// </summary> /// <param name="context"></param> /// <returns></returns> public Task <bool> ResumeTopic(NumberBotContext context) { // simply prompt again based on our state return(this.PromptForMissingData(context)); // Resume Topic - return }
private async Task <bool> ProcessTopicState(NumberBotContext context) { string utterance = (context.Activity.AsMessageActivity().Text ?? "").Trim(); // process without confirmation this.TopicState = TopicStates.AddConfirmation; this.Game.Title = utterance; if (context.UserState.Games == null) { context.UserState.Games = new List <Game>(); } context.UserState.Games.Add(this.Game); //await AddGameResponses.ReplyWithAddedAlarm(context, this.Game); // get values int guessedNumber = Convert.ToInt32(utterance); int secretNumber = context.UserState.SecretNumber; int minNumber = context.UserState.MinNumber; int maxNumber = context.UserState.MaxNumber; // calculate if (guessedNumber == secretNumber) { this.Guess.Comp = 0; // correct } else { if (guessedNumber > secretNumber) { if (guessedNumber < maxNumber) { maxNumber = guessedNumber; } this.Guess.Comp = 1; // too high } else if (guessedNumber < secretNumber) { if (guessedNumber > minNumber) { minNumber = guessedNumber; } this.Guess.Comp = -1; // too low } // guess again! } // update user state this.Guess.GuessValue = guessedNumber; if (context.UserState.Guesses == null) { context.UserState.Guesses = new List <Guess>(); } context.UserState.Guesses.Add(this.Guess); await AddGameResponses.ReplyWithAddedGuess(context, this.Guess); return(false); //we are using TopicState to remember what we last asked //switch (this.TopicState) //{ // case TopicStates.TitlePrompt: // this.Game.Title = utterance; // return await this.PromptForMissingData(context); // Process Topic State - Title Prompt // case TopicStates.AddConfirmation: // switch (context.RecognizedIntents.TopIntent?.Name) // { // case "confirmYes": // if (context.UserState.Games == null) // { // context.UserState.Games = new List<Game>(); // } // context.UserState.Games.Add(this.Game); // await AddGameResponses.ReplyWithAddedAlarm(context, this.Game); // // end topic // return false; // case "confirmNo": // await AddGameResponses.ReplyWithTopicCanceled(context); // // End current topic // return false; // default: // return await this.PromptForMissingData(context); // Process Topic State - Add Confirmation (default) // } // default: // return await this.PromptForMissingData(context); // Process Topic State - default //} }
public static async Task ShowGames(NumberBotContext context) { await ShowGamesResponses.ReplyWithShowGames(context, context.UserState.Guesses); }
public Task <bool> ResumeTopic(NumberBotContext context) { throw new System.NotImplementedException(); }