BotFrameworkHttpClient Class

public class BotFrameworkHttpClient
extends BotFrameworkClient

Class for posting activities securely to a bot using BotFramework HTTP protocol. This class can be used to securely post activities to a bot using the Bot Framework HTTP protocol. There are 2 usage patterns:* Forwarding activity to a Skill (Bot -> Bot as a Skill) which is done via PostActivity(fromBotId, toBotId, endpoint, serviceUrl, activity);* Posting an activity to yourself (External service -> Bot) which is done via PostActivity(botId, endpoint, activity)The latter is used by external services such as webjobs that need to post activities to the bot using the bots own credentials.

Constructor Summary

Constructor Description
BotFrameworkHttpClient(CredentialProvider credentialProvider, ChannelProvider channelProvider)

Initializes a new instance of the BotFrameworkHttpClient class.

Method Summary

Modifier and Type Method and Description
java.util.concurrent.CompletableFuture<TypedInvokeResponse<T>> <T>postActivity(String fromBotId, String toBotId, URI toUrl, URI serviceUrl, String conversationId, Activity activity, Class<T> type)

Forwards an activity to a skill (bot).

java.util.concurrent.CompletableFuture<TypedInvokeResponse<T>> <T>postActivity(String botId, URI botEndpoint, Activity activity, Class<T> type)

Post Activity to the bot using the bot's credentials.

protected java.util.concurrent.CompletableFuture<AppCredentials> buildCredentials(String appId, String oAuthScope)

Logic to build an AppCredentials Object to be used to acquire tokens for this getHttpClient().

protected static java.util.Map<java.lang.String,AppCredentials> getAppCredentialMapCache()

Gets the Cache for appCredentials to speed up token acquisition (a token is not requested unless is expired).

protected ChannelProvider getChannelProvider()

Gets the channel provider for this adapter.

protected CredentialProvider getCredentialProvider()

Gets the credential provider for this adapter.

okhttp3.OkHttpClient getHttpClient()

Gets the HttpClient for this adapter.

Methods inherited from BotFrameworkClient

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

BotFrameworkHttpClient

public BotFrameworkHttpClient(CredentialProvider credentialProvider, ChannelProvider channelProvider)

Initializes a new instance of the BotFrameworkHttpClient class.

Parameters:

credentialProvider - An instance of CredentialProvider .
channelProvider - An instance of ChannelProvider .

Method Details

<T>postActivity

public CompletableFuture> postActivity(String fromBotId, String toBotId, URI toUrl, URI serviceUrl, String conversationId, Activity activity, Class type)

Forwards an activity to a skill (bot). NOTE: Forwarding an activity to a skill will flush UserState and ConversationState changes so that skill has accurate state.

Overrides:

BotFrameworkHttpClient.<T>postActivity(String fromBotId, String toBotId, URI toUrl, URI serviceUrl, String conversationId, Activity activity, Class<T> type)

Parameters:

fromBotId - The MicrosoftAppId of the bot sending the activity.
toBotId - The MicrosoftAppId of the bot receiving the activity.
toUrl - The URL of the bot receiving the activity.
serviceUrl - The callback Url for the skill host.
conversationId - A conversation D to use for the conversation with the skill.
activity - activity to forward.
type

Returns:

task with optional invokeResponse.

<T>postActivity

public CompletableFuture> postActivity(String botId, URI botEndpoint, Activity activity, Class type)

Post Activity to the bot using the bot's credentials.

Parameters:

botId - The MicrosoftAppId of the bot.
botEndpoint - The URL of the bot.
activity - Activity to post.
type - Type of <T>.

Returns:

InvokeResponse.

buildCredentials

protected CompletableFuture buildCredentials(String appId, String oAuthScope)

Logic to build an AppCredentials Object to be used to acquire tokens for this getHttpClient().

Parameters:

appId - The application id.
oAuthScope - The optional OAuth scope.

Returns:

The app credentials to be used to acquire tokens.

getAppCredentialMapCache

protected static Map getAppCredentialMapCache()

Gets the Cache for appCredentials to speed up token acquisition (a token is not requested unless is expired). AppCredentials are cached using appId + scope (this last parameter is only used if the app credentials are used to call a skill).

Returns:

the AppCredentialMapCache value as a static ConcurrentDictionary<String, AppCredentials>.

getChannelProvider

protected ChannelProvider getChannelProvider()

Gets the channel provider for this adapter.

Returns:

the ChannelProvider value as a getChannelProvider().

getCredentialProvider

protected CredentialProvider getCredentialProvider()

Gets the credential provider for this adapter.

Returns:

the CredentialProvider value as a getCredentialProvider().

getHttpClient

public OkHttpClient getHttpClient()

Gets the HttpClient for this adapter.

Returns:

the OkhttpClient value as a getHttpClient().

Applies to