Table of Contents

Class ChannelServiceAdapterBase

Namespace
Microsoft.Agents.Builder
Assembly
Microsoft.Agents.Builder.dll

An adapter that implements the Activity Protocol and can be hosted in different cloud environments both public and private.

public abstract class ChannelServiceAdapterBase : ChannelAdapter, IChannelAdapter
Inheritance
ChannelServiceAdapterBase
Implements
Inherited Members

Constructors

ChannelServiceAdapterBase(IChannelServiceClientFactory, ILogger)

An adapter that implements the Activity Protocol and can be hosted in different cloud environments both public and private.

protected ChannelServiceAdapterBase(IChannelServiceClientFactory channelServiceClientFactory, ILogger logger = null)

Parameters

channelServiceClientFactory IChannelServiceClientFactory

The IConnectorFactory to use.

logger ILogger

The ILogger implementation this adapter should use.

Properties

ChannelServiceFactory

Gets the IChannelServiceClientFactory instance for this adapter.

protected IChannelServiceClientFactory ChannelServiceFactory { get; }

Property Value

IChannelServiceClientFactory

The IChannelServiceClientFactory instance for this adapter.

Logger

Gets a ILogger to use within this adapter and its subclasses.

protected ILogger Logger { get; }

Property Value

ILogger

The ILogger instance for this adapter.

Methods

ContinueConversationAsync(ClaimsIdentity, ConversationReference, AgentCallbackHandler, CancellationToken)

Sends a proactive message to a conversation.

public override Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, ConversationReference reference, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

claimsIdentity ClaimsIdentity

A ClaimsIdentity for the conversation.

reference ConversationReference

A reference to the conversation to continue.

callback AgentCallbackHandler

The method to call for the resulting Agent turn.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

Remarks

Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with an Agent before the Agent can send activities to the user.

ContinueConversationAsync(ClaimsIdentity, ConversationReference, string, AgentCallbackHandler, CancellationToken)

Sends a proactive message to a conversation.

public override Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, ConversationReference reference, string audience, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

claimsIdentity ClaimsIdentity

A ClaimsIdentity for the conversation.

reference ConversationReference

A reference to the conversation to continue.

audience string

A value signifying the recipient of the proactive message.

callback AgentCallbackHandler

The method to call for the resulting Agent turn.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

Remarks

Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with an Agent before the Agent can send activities to the user.

ContinueConversationAsync(ClaimsIdentity, IActivity, AgentCallbackHandler, CancellationToken)

Sends a proactive message to a conversation.

public override Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, IActivity continuationActivity, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

claimsIdentity ClaimsIdentity

A ClaimsIdentity for the conversation.

continuationActivity IActivity

An Microsoft.Agents.Core.Models.Activity with the appropriate Microsoft.Agents.Core.Models.ConversationReference with which to continue the conversation.

callback AgentCallbackHandler

The method to call for the resulting Agent turn.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

A task that represents the work queued to execute.

Remarks

Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with an Agent before the Agent can send activities to the user.

ContinueConversationAsync(ClaimsIdentity, IActivity, string, AgentCallbackHandler, CancellationToken)

Sends a proactive message to a conversation.

public override Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, IActivity continuationActivity, string audience, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

claimsIdentity ClaimsIdentity

A ClaimsIdentity for the conversation.

continuationActivity IActivity

An Microsoft.Agents.Core.Models.Activity with the appropriate Microsoft.Agents.Core.Models.ConversationReference with which to continue the conversation.

audience string

A value signifying the recipient of the proactive message.

callback AgentCallbackHandler

The method to call for the resulting Agent turn.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

Remarks

Call this method to proactively send a message to a conversation. Most _channels require a user to initiate a conversation with an Agent before the Agent can send activities to the user.

ContinueConversationAsync(string, ConversationReference, AgentCallbackHandler, CancellationToken)

Sends a proactive message to a conversation.

public override Task ContinueConversationAsync(string agentAppId, ConversationReference reference, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

agentAppId string
reference ConversationReference

A reference to the conversation to continue.

callback AgentCallbackHandler

The method to call for the resulting Agent turn.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

Remarks

Call this method to proactively send a message to a conversation. Most _channels require a user to initiate a conversation with an Agent before the Agent can send activities to the user.

ContinueConversationAsync(string, IActivity, AgentCallbackHandler, CancellationToken)

Sends a proactive message to a conversation.

public override Task ContinueConversationAsync(string agentAppId, IActivity continuationActivity, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

agentAppId string
continuationActivity IActivity

An Microsoft.Agents.Core.Models.Activity with the appropriate Microsoft.Agents.Core.Models.ConversationReference with which to continue the conversation.

callback AgentCallbackHandler

The method to call for the resulting Agent turn.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

Remarks

Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with an Agent before the Agent can send activities to the user.

CreateClaimsIdentity(string)

This is a helper to create the ClaimsIdentity structure from an appId that will be added to the TurnContext. It is intended for use in proactive and named-pipe scenarios.

protected static ClaimsIdentity CreateClaimsIdentity(string agentAppId)

Parameters

agentAppId string

The Agent's application id.

Returns

ClaimsIdentity

A ClaimsIdentity with the audience and appId claims set to the appId.

CreateConversationAsync(string, string, string, string, ConversationParameters, AgentCallbackHandler, CancellationToken)

Creates a conversation on the specified channel.

public override Task CreateConversationAsync(string agentAppId, string channelId, string serviceUrl, string audience, ConversationParameters conversationParameters, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

agentAppId string

TThe application ID of the Agent.

channelId string

The ID for the channel.

serviceUrl string

The channel's service URL endpoint.

audience string

The audience for the connector.

conversationParameters ConversationParameters

The conversation information to use to create the conversation.

callback AgentCallbackHandler

The method to call for the resulting Agent turn.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

Remarks

To start a conversation, your Agent must know its account information and the user's account information on that channel. Most channels only support initiating a direct message (non-group) conversation.

The adapter attempts to create a new conversation on the channel, and then sends a conversationUpdate Activity through its middleware pipeline to the callback method.

If the conversation is established with the specified users, the ID of the activity's Microsoft.Agents.Core.Models.Activity.Conversation will contain the ID of the new conversation.

DeleteActivityAsync(ITurnContext, ConversationReference, CancellationToken)

When overridden in a derived class, deletes an existing activity in the conversation.

public override Task DeleteActivityAsync(ITurnContext turnContext, ConversationReference reference, CancellationToken cancellationToken)

Parameters

turnContext ITurnContext

The context object for the turn.

reference ConversationReference

Conversation reference for the activity to delete.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

Remarks

The Microsoft.Agents.Core.Models.ConversationReference.ActivityId of the conversation reference identifies the activity to delete.

See Also

ProcessActivityAsync(ClaimsIdentity, IActivity, AgentCallbackHandler, CancellationToken)

Creates a turn context and runs the middleware pipeline for an incoming TRUSTED activity.

public override Task<InvokeResponse> ProcessActivityAsync(ClaimsIdentity claimsIdentity, IActivity activity, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

claimsIdentity ClaimsIdentity

A ClaimsIdentity for the request.

activity IActivity

The incoming activity.

callback AgentCallbackHandler

The code to run at the end of the adapter's middleware pipeline.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<InvokeResponse>

If an Invoke Activity was received, an Microsoft.Agents.Core.Models.InvokeResponse, otherwise null.

ProcessProactiveAsync(ClaimsIdentity, IActivity, IAgent, CancellationToken, string)

public override Task ProcessProactiveAsync(ClaimsIdentity claimsIdentity, IActivity continuationActivity, IAgent agent, CancellationToken cancellationToken, string audience = null)

Parameters

claimsIdentity ClaimsIdentity
continuationActivity IActivity
agent IAgent
cancellationToken CancellationToken
audience string

Returns

Task

ProcessProactiveAsync(ClaimsIdentity, IActivity, string, AgentCallbackHandler, CancellationToken)

The implementation for continue conversation.

public override Task ProcessProactiveAsync(ClaimsIdentity claimsIdentity, IActivity continuationActivity, string audience, AgentCallbackHandler callback, CancellationToken cancellationToken)

Parameters

claimsIdentity ClaimsIdentity

A ClaimsIdentity for the conversation.

continuationActivity IActivity

The continuation Microsoft.Agents.Core.Models.Activity used to create the ITurnContext.

audience string

The audience for the call.

callback AgentCallbackHandler

The method to call for the resulting Agent turn.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

A task that represents the work queued to execute.

SendActivitiesAsync(ITurnContext, IActivity[], CancellationToken)

When overridden in a derived class, sends activities to the conversation.

public override Task<ResourceResponse[]> SendActivitiesAsync(ITurnContext turnContext, IActivity[] activities, CancellationToken cancellationToken)

Parameters

turnContext ITurnContext

The context object for the turn.

activities IActivity[]

The activities to send.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<ResourceResponse[]>

If the activities are successfully sent, the task result contains an array of Microsoft.Agents.Core.Models.ResourceResponse objects containing the IDs that the receiving channel assigned to the activities.

See Also

StreamedResponseAsync(IActivity, IActivity, CancellationToken)

protected virtual Task<bool> StreamedResponseAsync(IActivity incomingActivity, IActivity outActivity, CancellationToken cancellationToken)

Parameters

incomingActivity IActivity
outActivity IActivity
cancellationToken CancellationToken

Returns

Task<bool>

UpdateActivityAsync(ITurnContext, IActivity, CancellationToken)

When overridden in a derived class, replaces an existing activity in the conversation.

public override Task<ResourceResponse> UpdateActivityAsync(ITurnContext turnContext, IActivity activity, CancellationToken cancellationToken)

Parameters

turnContext ITurnContext

The context object for the turn.

activity IActivity

New replacement activity.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<ResourceResponse>

If the activity is successfully sent, the task result contains a Microsoft.Agents.Core.Models.ResourceResponse object containing the ID that the receiving channel assigned to the activity.

Before calling this, set the ID of the replacement activity to the ID of the activity to replace.

See Also