Share via


ConversationThreadClient.AddParticipantsAsync Method

Definition

Overloads

AddParticipantsAsync(String, AddParticipantsOptions, CancellationToken)

Adds participants to a specific conversation.

AddParticipantsAsync(String, RequestContent, RequestContext)

[Protocol Method] Adds participants to a specific conversation.

AddParticipantsAsync(String, AddParticipantsOptions, CancellationToken)

Source:
ConversationThreadClient.cs

Adds participants to a specific conversation.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Messages.AddParticipantsResult>> AddParticipantsAsync(string conversationId, Azure.Communication.Messages.AddParticipantsOptions options, System.Threading.CancellationToken cancellationToken = default);
abstract member AddParticipantsAsync : string * Azure.Communication.Messages.AddParticipantsOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Messages.AddParticipantsResult>>
override this.AddParticipantsAsync : string * Azure.Communication.Messages.AddParticipantsOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Messages.AddParticipantsResult>>
Public Overridable Function AddParticipantsAsync (conversationId As String, options As AddParticipantsOptions, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AddParticipantsResult))

Parameters

conversationId
String

The conversation ID.

options
AddParticipantsOptions

Details of the payload for adding participants to a conversation.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

conversationId or options is null.

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

Examples

This sample shows how to call AddParticipantsAsync.

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

AddParticipantsOptions options = new AddParticipantsOptions(new ConversationParticipant[]
{
    new InternalConversationParticipant(new CommunicationContact("<id>"))
});
Response<AddParticipantsResult> response = await client.AddParticipantsAsync("<conversationId>", options);

This sample shows how to call AddParticipantsAsync with all parameters.

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

AddParticipantsOptions options = new AddParticipantsOptions(new ConversationParticipant[]
{
    new InternalConversationParticipant(new CommunicationContact("<id>"))
    {
        DisplayName = "<displayName>",
    }
});
Response<AddParticipantsResult> response = await client.AddParticipantsAsync("<conversationId>", options);

Applies to

AddParticipantsAsync(String, RequestContent, RequestContext)

Source:
ConversationThreadClient.cs

[Protocol Method] Adds participants to a specific conversation.

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

Parameters

conversationId
String

The conversation ID.

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

conversationId or content 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 AddParticipantsAsync and parse the result.

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

using RequestContent content = RequestContent.Create(new
{
    participants = new object[]
    {
        new
        {
            kind = "internal",
            contact = new
            {
                kind = "communication",
                id = "<id>",
            },
        }
    },
});
Response response = await client.AddParticipantsAsync("<conversationId>", content);

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

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

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

using RequestContent content = RequestContent.Create(new
{
    participants = new object[]
    {
        new
        {
            kind = "internal",
            contact = new
            {
                kind = "communication",
                id = "<id>",
            },
            displayName = "<displayName>",
        }
    },
});
Response response = await client.AddParticipantsAsync("<conversationId>", content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("invalidParticipants")[0].GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("invalidParticipants")[0].GetProperty("error").GetProperty("code").ToString());
Console.WriteLine(result.GetProperty("invalidParticipants")[0].GetProperty("error").GetProperty("message").ToString());
Console.WriteLine(result.GetProperty("invalidParticipants")[0].GetProperty("error").GetProperty("target").ToString());
Console.WriteLine(result.GetProperty("invalidParticipants")[0].GetProperty("error").GetProperty("innererror").GetProperty("code").ToString());

Applies to