Share via


ConversationThreadClient.GetMessagesAsync Method

Definition

Overloads

GetMessagesAsync(String, Nullable<Int32>, String, RequestContext)

[Protocol Method] Retrieves list of conversation messages.

GetMessagesAsync(String, Nullable<Int32>, String, CancellationToken)

Retrieves list of conversation messages.

GetMessagesAsync(String, Nullable<Int32>, String, RequestContext)

Source:
ConversationThreadClient.cs

[Protocol Method] Retrieves list of conversation messages.

public virtual Azure.AsyncPageable<BinaryData> GetMessagesAsync(string conversationId, int? maxPageSize, string participantId, Azure.RequestContext context);
abstract member GetMessagesAsync : string * Nullable<int> * string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
override this.GetMessagesAsync : string * Nullable<int> * string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
Public Overridable Function GetMessagesAsync (conversationId As String, maxPageSize As Nullable(Of Integer), participantId As String, context As RequestContext) As AsyncPageable(Of BinaryData)

Parameters

conversationId
String

The conversation ID.

maxPageSize
Nullable<Int32>

Number of objects to return per page.

participantId
String

The participant user ID.

context
RequestContext

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

Returns

The AsyncPageable<T> from the service containing a list of BinaryData objects. Details of the body schema for each item in the collection are in the Remarks section below.

Exceptions

conversationId is null.

conversationId is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

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

Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
ConversationThreadClient client = new ConversationThreadClient(endpoint, credential);

await foreach (BinaryData item in client.GetMessagesAsync("<conversationId>", null, null, null))
{
    JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("id").ToString());
    Console.WriteLine(result.GetProperty("message").GetProperty("kind").ToString());
    Console.WriteLine(result.GetProperty("senderCommunicationIdentifier").ToString());
    Console.WriteLine(result.GetProperty("createdOn").ToString());
}

This sample shows how to call GetMessagesAsync with all parameters and parse the result.

Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
ConversationThreadClient client = new ConversationThreadClient(endpoint, credential);

await foreach (BinaryData item in client.GetMessagesAsync("<conversationId>", 1234, "<participantId>", null))
{
    JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("id").ToString());
    Console.WriteLine(result.GetProperty("sequenceId").ToString());
    Console.WriteLine(result.GetProperty("message").GetProperty("kind").ToString());
    Console.WriteLine(result.GetProperty("senderDisplayName").ToString());
    Console.WriteLine(result.GetProperty("senderCommunicationIdentifier").ToString());
    Console.WriteLine(result.GetProperty("createdOn").ToString());
}

Applies to

GetMessagesAsync(String, Nullable<Int32>, String, CancellationToken)

Source:
ConversationThreadClient.cs

Retrieves list of conversation messages.

public virtual Azure.AsyncPageable<Azure.Communication.Messages.ConversationMessageItem> GetMessagesAsync(string conversationId, int? maxPageSize = default, string participantId = default, System.Threading.CancellationToken cancellationToken = default);
abstract member GetMessagesAsync : string * Nullable<int> * string * System.Threading.CancellationToken -> Azure.AsyncPageable<Azure.Communication.Messages.ConversationMessageItem>
override this.GetMessagesAsync : string * Nullable<int> * string * System.Threading.CancellationToken -> Azure.AsyncPageable<Azure.Communication.Messages.ConversationMessageItem>
Public Overridable Function GetMessagesAsync (conversationId As String, Optional maxPageSize As Nullable(Of Integer) = Nothing, Optional participantId As String = Nothing, Optional cancellationToken As CancellationToken = Nothing) As AsyncPageable(Of ConversationMessageItem)

Parameters

conversationId
String

The conversation ID.

maxPageSize
Nullable<Int32>

Number of objects to return per page.

participantId
String

The participant user ID.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

conversationId is null.

conversationId is an empty string, and was expected to be non-empty.

Examples

This sample shows how to call GetMessagesAsync.

Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
ConversationThreadClient client = new ConversationThreadClient(endpoint, credential);

await foreach (ConversationMessageItem item in client.GetMessagesAsync("<conversationId>"))
{
}

This sample shows how to call GetMessagesAsync with all parameters.

Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
ConversationThreadClient client = new ConversationThreadClient(endpoint, credential);

await foreach (ConversationMessageItem item in client.GetMessagesAsync("<conversationId>", maxPageSize: 1234, participantId: "<participantId>"))
{
}

Applies to