你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

NotificationMessagesClient.SendAsync Method

Definition

Overloads

SendAsync(NotificationContent, CancellationToken)

Sends a notification message from Business to User.

SendAsync(RequestContent, RequestContext)

[Protocol Method] Sends a notification message from Business to User.

SendAsync(NotificationContent, CancellationToken)

Source:
NotificationMessagesClient.cs

Sends a notification message from Business to User.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Messages.SendMessageResult>> SendAsync (Azure.Communication.Messages.NotificationContent notificationContent, System.Threading.CancellationToken cancellationToken = default);
abstract member SendAsync : Azure.Communication.Messages.NotificationContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Messages.SendMessageResult>>
override this.SendAsync : Azure.Communication.Messages.NotificationContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Messages.SendMessageResult>>
Public Overridable Function SendAsync (notificationContent As NotificationContent, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of SendMessageResult))

Parameters

notificationContent
NotificationContent

Details of the message to send.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

notificationContent is null.

Examples

This sample shows how to call SendAsync.

NotificationMessagesClient client = new NotificationMessagesClient(null);

NotificationContent notificationContent = new TextNotificationContent(Guid.Parse("73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a"), new string[] { "<to>" }, "<content>");
Response<SendMessageResult> response = await client.SendAsync(notificationContent);

This sample shows how to call SendAsync with all parameters.

NotificationMessagesClient client = new NotificationMessagesClient(null);

NotificationContent notificationContent = new TextNotificationContent(Guid.Parse("73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a"), new string[] { "<to>" }, "<content>");
Response<SendMessageResult> response = await client.SendAsync(notificationContent);

Applies to

SendAsync(RequestContent, RequestContext)

Source:
NotificationMessagesClient.cs

[Protocol Method] Sends a notification message from Business to User.

public virtual System.Threading.Tasks.Task<Azure.Response> SendAsync (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member SendAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.SendAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function SendAsync (content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

content is null.

Service returned a non-success status code.

Examples

This sample shows how to call SendAsync and parse the result.

NotificationMessagesClient client = new NotificationMessagesClient(null);

using RequestContent content = RequestContent.Create(new
{
    content = "<content>",
    channelRegistrationId = "73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a",
    to = new object[]
    {
        "<to>"
    },
    kind = "text",
});
Response response = await client.SendAsync(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("receipts")[0].GetProperty("messageId").ToString());
Console.WriteLine(result.GetProperty("receipts")[0].GetProperty("to").ToString());

This sample shows how to call SendAsync with all request content and parse the result.

NotificationMessagesClient client = new NotificationMessagesClient(null);

using RequestContent content = RequestContent.Create(new
{
    content = "<content>",
    channelRegistrationId = "73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a",
    to = new object[]
    {
        "<to>"
    },
    kind = "text",
});
Response response = await client.SendAsync(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("receipts")[0].GetProperty("messageId").ToString());
Console.WriteLine(result.GetProperty("receipts")[0].GetProperty("to").ToString());

Applies to