BotApplication.OnActivity Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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);
}
};