Skip to content

Is there anyway to send message from bot onError #116

@yuqizhou77

Description

@yuqizhou77

Use such code snippet in program.cs to have bot send an general message back to users if there is any error happens. However the context is null so that I cannot send message back.

Repro steps:

  1. Open Samples.Echo
  2. Replace the main method with the content below
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);
        builder.Services.AddOpenApi();
        //builder.Services.AddTransient<Controller>();
        builder.AddTeams().AddTeamsDevTools();

        var app = builder.Build();

        if (app.Environment.IsDevelopment())
        {
            app.MapOpenApi();
        }

        app.UseHttpsRedirection();
        var teamsApp = app.UseTeams();

        teamsApp.OnMessage(async (context) =>
        {
            throw new Exception("test exception");
        });

        teamsApp.OnError(async (sender, @event) =>
        {
            Console.WriteLine("!!OnError HIT!!");
            var context = @event.Context;
            await context.Send($"The bot encountered an unhandled error: {@event.Exception.Message}");
            teamsApp.Logger.Error($"[OnError] unhandled error : {@event.Exception.Message}");
        });

        app.Run();
    }

  1. context is null that cannot send message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions