Skip to content

Instantly share code, notes, and snippets.

using Microsoft.Bot.Builder.Adapters.Twilio;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace AppointmentBot
{
public class TwilioAdapterWithErrorHandler : TwilioAdapter
{
public TwilioAdapterWithErrorHandler(IConfiguration configuration, ILogger<TwilioAdapter> logger)
private async Task<DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
if (!_luisRecognizer.IsConfigured)
{
// LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance.
return await stepContext.BeginDialogAsync(nameof(AppointmentBookingDialog), new AppointmentDetails(), cancellationToken);
}
// Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)
var luisResult = await _luisRecognizer.RecognizeAsync<DoctorBooking>(stepContext.Context, cancellationToken);
public class AppointmentBookingDialog : CancelAndHelpDialog
{
private const string DoctorStepMsgText = "Who would you like to see?";
public AppointmentBookingDialog()
: base(nameof(AppointmentBookingDialog))
{
AddDialog(new TextPrompt(nameof(TextPrompt)));
AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
namespace AppointmentBot
{
public class AppointmentDetails
{
public string Doctor { get; set; }
public string AppointmentDate { get; set; }
}
}
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.Luis;
using Microsoft.Extensions.Configuration;
using System.Threading;
using System.Threading.Tasks;
namespace AppointmentBot
{
public class AppointmentBookingRecognizer : IRecognizer
{
using System.Linq;
namespace AppointmentBot.CognitiveModels
{
// Extends the partial DoctorBooking class with methods and properties that simplify accessing entities in the luis results
public partial class DoctorBooking
{
public string Doctor
{
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.Luis;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace AppointmentBot.CognitiveModels
{
public partial class DoctorBooking : IRecognizerConvert
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient().AddControllers().AddNewtonsoftJson();
// Create the Bot Framework Authentication to be used with the Bot Adapter.
services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFrameworkAuthentication>();
// Register LUIS recognizer
services.AddSingleton<FlightBookingRecognizer>();
// Register the BookingDialog.
services.AddSingleton<BookingDialog>();
// The MainDialog that will be run by the bot.
services.AddSingleton<MainDialog>();
// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
Remove-Item ./CognitiveModels/FlightBooking.cs
Remove-Item ./CognitiveModels/FlightBooking.json
Remove-Item ./CognitiveModels/FlightBookingEx.cs
Remove-Item ./Dialogs/BookingDialog.cs
Remove-Item ./Dialogs/MainDialog.cs
Remove-Item BookingDetails.cs
Remove-Item FlightBookingRecognizer.cs