This article is a step-by-step guide on how to create a Bot from scratch using Microsoft Bot Framework and how to configure it to work with Microsoft Teams.
Navigate and log in to Azure Portal. Create a new resource group then add a new Web App Bot (You can type “bot” in the search bar to filter your results).
After you click on the Create button, you will be redirected to the configuration page of your resource.
Since you added the resource directly from the resource group, some properties will be automatically set to the resource group values (like Resource group, Location, and Subscription).
Let’s fill up the remaining properties as follow:
To complete the configuration and create the resource click Create and wait a few seconds to allow Azure to complete the task in the background. From the Channels tab under Bot Management, click on the Microsoft Teams icon to add the MS Teams channel to the bot.
Open Visual Studio and create a new empty .NET Core web application project. It’s possible to start from a Skill Template but it comes with many pre-added features (like CosmosDb, Monitoring, Multilanguage, and many more) which might confuse you and for the purpose of this demo I prefer to start with a barebone bot.
Open the Package Manager Console and execute the following instruction to add the required dependencies:
Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson
Install-Package Microsoft.Bot.Builder
Install-Package Microsoft.Bot.Builder.Integration.AspNet.Core
Now it’s time to add services to our collection and make them available in our application through dependency injection and configure the middleware pipeline:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Pegasus.Bots;
namespace Pegasus
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddNewtonsoftJson();
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
services.AddTransient<IBot, PegasusBot>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles()
.UseStaticFiles()
.UseWebSockets()
.UseRouting()
.UseAuthorization()
.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
#microsoft-teams #bots #microsoft #coding #tutorial