Articles → MICROSOFT BOT FRAMEWORK → Create Your First Dialog In Microsoft Bot Framework

Create Your First Dialog In Microsoft Bot Framework






What Is Dialog?





How To Create Your Own Dialog?




  1. Create a new class "WelcomeDialog".
  2. Implement the "IDialog" interface.
  3. Implement the "Async" method.
  4. using Microsoft.Bot.Builder.Dialogs;
    using System;
    using System.Threading.Tasks;
    
    namespace Bot_Application1.Dialogs { 
    	[Serializable]
    	public class WelcomeDialog: IDialog < object > {
    		public Task StartAsync(IDialogContext context) {
    			context.Wait(PerformActionAsync);
    			return Task.CompletedTask;
    		}
    
    		private async Task PerformActionAsync(IDialogContext context, IAwaitable < object > result) {
    			var activity = await result as Microsoft.Bot.Connector.Activity;
    
    			if (activity.Text == "hi") {
    				await context.PostAsync("Hi How are you");
    			}
    			else await context.PostAsync("Please say it again");
    
    		}
    	}
    }




  5. Call the "WelcomeDialog" class inside the "MessageController" class.
Picture showing calling the WelcomeDialog class inside the MessageController
Click to Enlarge


Output


Picture showing the output of welcome dialog in Microsoft bot framework
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, October 12, 2020

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250