BotApplication.SendActivityAsync Method
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.
Sends the specified activity to the conversation asynchronously.
public System.Threading.Tasks.Task<Microsoft.Teams.Core.SendActivityResponse?> SendActivityAsync(string conversationId, Microsoft.Teams.Core.Schema.CoreActivityInput activity, Uri serviceUrl, Microsoft.Teams.Core.Schema.AgenticIdentity? agenticIdentity = default, bool isTargeted = false, System.Threading.CancellationToken cancellationToken = default);
member this.SendActivityAsync : string * Microsoft.Teams.Core.Schema.CoreActivityInput * Uri * Microsoft.Teams.Core.Schema.AgenticIdentity * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Teams.Core.SendActivityResponse>
Public Function SendActivityAsync (conversationId As String, activity As CoreActivityInput, serviceUrl As Uri, Optional agenticIdentity As AgenticIdentity = Nothing, Optional isTargeted As Boolean = false, Optional cancellationToken As CancellationToken = Nothing) As Task(Of SendActivityResponse)
Parameters
- conversationId
- String
The id of the conversation to send the activity to.
- activity
- CoreActivityInput
The activity to send. Cannot be null.
- serviceUrl
- Uri
The service url to send the activity to.
- agenticIdentity
- AgenticIdentity
Optional agentic identity for user-delegated token acquisition.
- isTargeted
- Boolean
Optional flag indicating whether the activity is a targeted message (visible only to the recipient).
- cancellationToken
- CancellationToken
A cancellation token that can be used to cancel the send operation.
Returns
A task that represents the asynchronous operation. The task result contains a SendActivityResponse with the ID of the sent activity, or null.
Exceptions
Thrown if activity is null or the conversation client has not been initialized.
Remarks
This is a convenience wrapper around ConversationClient.SendActivityAsync. Routing is passed explicitly via conversationId and serviceUrl; the activity itself only needs to carry content.
var reply = CoreActivityInput.CreateBuilder()
.WithType(ActivityType.Message)
.WithProperty("text", "Hello from the bot!")
.Build();
SendActivityResponse? response = await bot.SendActivityAsync(
incomingActivity.Conversation.Id!, reply, incomingActivity.ServiceUrl!, cancellationToken);
string? sentId = response?.Id;