Language

BotApplication.OnActivity Property

Definition

Gets or sets the delegate that is invoked to handle each incoming activity.

public virtual Func<Microsoft.Teams.Core.Schema.CoreActivity,System.Threading.CancellationToken,System.Threading.Tasks.Task>? OnActivity { get; set; }
member this.OnActivity : Func<Microsoft.Teams.Core.Schema.CoreActivity, System.Threading.CancellationToken, System.Threading.Tasks.Task> with get, set
Public Overridable Property OnActivity As Func(Of CoreActivity, CancellationToken, Task)

Property Value

Remarks

Assign a handler to process activities as they arrive. If null, incoming activities pass through the middleware pipeline but are otherwise ignored.

bot.OnActivity = async (activity, ct) =>
{
    if (activity.Type == ActivityType.Message)
    {
        await bot.SendActivityAsync(
            activity.Conversation.Id!,
            CoreActivityInput.CreateBuilder()
                .WithType(ActivityType.Message)
                .WithProperty("text", "Received your message!")
                .Build(),
            activity.ServiceUrl!,
            ct);
    }
};

Applies to