Created
July 15, 2016 12:24
-
-
Save beachside-project/82239653f750a1a44c98332ba94d3b83 to your computer and use it in GitHub Desktop.
StateEchoDialog
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
using System; | |
using System.Threading.Tasks; | |
using Microsoft.Bot.Builder.Dialogs; | |
using Microsoft.Bot.Connector; | |
namespace DialogDemo.Dialogs | |
{ | |
[Serializable] | |
public class StateEchoDialog : IDialog<object> | |
{ | |
private const string ResetText = "reset"; | |
protected int _count; | |
#region public | |
public async Task StartAsync(IDialogContext context) | |
{ | |
InitCount(); | |
context.Wait(MessageReceivedAsync); | |
} | |
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument) | |
{ | |
var messageActivity = await argument; | |
if (messageActivity.Text == ResetText) | |
{ | |
PromptDialog.Confirm(context, | |
AfterResetAsync, | |
DialogSampleUtil.GetConfirmMessage(nameof(StateEchoDialog)), | |
BotMessage.NotGetThat, | |
promptStyle: PromptStyle.PerLine); | |
} | |
else | |
{ | |
await context.PostAsync(DialogSampleUtil.GetIncrementedMessage(_count++, messageActivity.Text)); | |
context.Wait(MessageReceivedAsync); | |
} | |
} | |
#endregion | |
#region private | |
public async Task AfterResetAsync(IDialogContext context, IAwaitable<bool> argument) | |
{ | |
var confirm = await argument; | |
if (confirm) | |
{ | |
InitCount(); | |
await context.PostAsync(BotMessage.ResetDone); | |
} | |
else | |
{ | |
await context.PostAsync(BotMessage.ResetCancelled); | |
} | |
context.Wait(MessageReceivedAsync); | |
} | |
private void InitCount() => _count = 1; | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment