In this blog series, we will create a ToDo bot that will allow you to Create, View and Delete Tasks.
In this part we will setup our development environment.
Video
Pre-requisites
- Visual Studio
- Bot Framework v4 Templates
- Bot Emulator
Above requirements links are available in Downloads page.
Creating a Core Bot project in Visual Studio
Kindly watch the below video or refer to the blog to create a Core Bot project using the templates. Will be continuing from the created core bot project. I have used the Core Bot template with .NET Core 3.1 version.
I will be giving the project name as ToDoBot. You can give any name you like for your requirement.
Editing the Project Structure
Remove the following files and folder which are not required for our requirement –
- BookingDetails.cs
- BookingDialog.cs
- CognitiveModels Folder
Rename the FlightBookingRecognizer.cs to ToDoLUISRecognizer.cs. Click on Yes to change all the references to this file.
Remove the following line of code from Startup.cs
// Register the BookingDialog.
services.AddSingleton<BookingDialog>();
Remove all the method content from all methods in MainDialog.cs. Also, remove the imports which are showing error. Add the return null; statement in all the methods where it is showing the error. Below is the MainDialog class will look like after above removal.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v4.11.1
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Logging;
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ToDoBot.Dialogs
{
public class MainDialog : ComponentDialog
{
private readonly ToDoLUISRecognizer _luisRecognizer;
protected readonly ILogger Logger;
// Dependency injection uses this constructor to instantiate MainDialog
public MainDialog(ToDoLUISRecognizer luisRecognizer, ILogger<MainDialog> logger)
: base(nameof(MainDialog))
{
_luisRecognizer = luisRecognizer;
Logger = logger;
AddDialog(new TextPrompt(nameof(TextPrompt)));
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
IntroStepAsync,
ActStepAsync,
FinalStepAsync,
}));
// The initial child Dialog to run.
InitialDialogId = nameof(WaterfallDialog);
}
private async Task<DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
return null;
}
private async Task<DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
return null;
}
private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
// Restart the main dialog with a different message the second time around
var promptMessage = "What else can I do for you?";
return await stepContext.ReplaceDialogAsync(InitialDialogId, promptMessage, cancellationToken);
}
}
}
In the next part we will create a welcome card for our bot.