ChannelServiceHandler Class

  • java.lang.Object
    • com.microsoft.bot.builder.ChannelServiceHandler

public class ChannelServiceHandler

A class to help with the implementation of the Bot Framework protocol.

Constructor Summary

Constructor Description
ChannelServiceHandler(CredentialProvider credentialProvider, AuthenticationConfiguration authConfiguration, ChannelProvider channelProvider)

Initializes a new instance of the ChannelServiceHandler class, using a credential provider.

Method Summary

Modifier and Type Method and Description
protected ChannelProvider getChannelProvider()

Gets the channel provider that implements ChannelProvider .

java.util.concurrent.CompletableFuture<ConversationResourceResponse> handleCreateConversation(String authHeader, ConversationParameters parameters)

Create a new Conversation.

java.util.concurrent.CompletableFuture<java.lang.Void> handleDeleteActivity(String authHeader, String conversationId, String activityId)

Deletes an existing activity.

java.util.concurrent.CompletableFuture<java.lang.Void> handleDeleteConversationMember(String authHeader, String conversationId, String memberId)

Deletes a member from a conversation.

java.util.concurrent.CompletableFuture<java.util.List<ChannelAccount>> handleGetActivityMembers(String authHeader, String conversationId, String activityId)

Enumerates the members of an activity.

java.util.concurrent.CompletableFuture<java.util.List<ChannelAccount>> handleGetConversationMembers(String authHeader, String conversationId)

Enumerates the members of a conversation.

java.util.concurrent.CompletableFuture<PagedMembersResult> handleGetConversationPagedMembers(String authHeader, String conversationId, Integer pageSize, String continuationToken)

Enumerates the members of a conversation one page at a time.

java.util.concurrent.CompletableFuture<ConversationsResult> handleGetConversations(String authHeader, String conversationId, String continuationToken)

Lists the Conversations in which the bot has participated.

java.util.concurrent.CompletableFuture<ResourceResponse> handleReplyToActivity(String authHeader, String conversationId, String activityId, Activity activity)

Sends a reply to an activity.

java.util.concurrent.CompletableFuture<ResourceResponse> handleSendConversationHistory(String authHeader, String conversationId, Transcript transcript)

Uploads the historic activities of the conversation.

java.util.concurrent.CompletableFuture<ResourceResponse> handleSendToConversation(String authHeader, String conversationId, Activity activity)

Sends an activity to the end of a conversation.

java.util.concurrent.CompletableFuture<ResourceResponse> handleUpdateActivity(String authHeader, String conversationId, String activityId, Activity activity)

Edits a previously sent existing activity.

java.util.concurrent.CompletableFuture<ResourceResponse> handleUploadAttachment(String authHeader, String conversationId, AttachmentData attachmentUpload)

Stores data in a compliant store when dealing with enterprises.

protected java.util.concurrent.CompletableFuture<ConversationResourceResponse> onCreateConversation(ClaimsIdentity claimsIdentity, ConversationParameters parameters)

CreateConversation() API.

protected java.util.concurrent.CompletableFuture<java.lang.Void> onDeleteActivity(ClaimsIdentity claimsIdentity, String conversationId, String activityId)

OnDeleteActivity() API.

protected java.util.concurrent.CompletableFuture<java.lang.Void> onDeleteConversationMember(ClaimsIdentity claimsIdentity, String conversationId, String memberId)

DeleteConversationMember() API for Skill.

protected java.util.concurrent.CompletableFuture<java.util.List<ChannelAccount>> onGetActivityMembers(ClaimsIdentity claimsIdentity, String conversationId, String activityId)

OnGetActivityMembers() API.

protected java.util.concurrent.CompletableFuture<java.util.List<ChannelAccount>> onGetConversationMembers(ClaimsIdentity claimsIdentity, String conversationId)

GetConversationMembers() API for Skill.

protected java.util.concurrent.CompletableFuture<PagedMembersResult> onGetConversationPagedMembers(ClaimsIdentity claimsIdentity, String conversationId, Integer pageSize, String continuationToken)

GetConversationPagedMembers() API for Skill.

protected java.util.concurrent.CompletableFuture<ConversationsResult> onGetConversations(ClaimsIdentity claimsIdentity, String conversationId, String continuationToken)

OnGetConversations() API for Skill.

protected java.util.concurrent.CompletableFuture<ResourceResponse> onReplyToActivity(ClaimsIdentity claimsIdentity, String conversationId, String activityId, Activity activity)

OnReplyToActivity() API.

protected java.util.concurrent.CompletableFuture<ResourceResponse> onSendConversationHistory(ClaimsIdentity claimsIdentity, String conversationId, Transcript transcript)

SendConversationHistory() API for Skill.

protected java.util.concurrent.CompletableFuture<ResourceResponse> onSendToConversation(ClaimsIdentity claimsIdentity, String conversationId, Activity activity)

SendToConversation() API for Skill.

protected java.util.concurrent.CompletableFuture<ResourceResponse> onUpdateActivity(ClaimsIdentity claimsIdentity, String conversationId, String activityId, Activity activity)

OnUpdateActivity() API.

protected java.util.concurrent.CompletableFuture<ResourceResponse> onUploadAttachment(ClaimsIdentity claimsIdentity, String conversationId, AttachmentData attachmentUpload)

UploadAttachment() API.

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

ChannelServiceHandler

public ChannelServiceHandler(CredentialProvider credentialProvider, AuthenticationConfiguration authConfiguration, ChannelProvider channelProvider)

Initializes a new instance of the ChannelServiceHandler class, using a credential provider.

Parameters:

credentialProvider - The credential provider.
authConfiguration - The authentication configuration.
channelProvider - The channel provider.

Method Details

getChannelProvider

protected ChannelProvider getChannelProvider()

Gets the channel provider that implements ChannelProvider .

Returns:

the ChannelProvider value as a getChannelProvider().

handleCreateConversation

public CompletableFuture handleCreateConversation(String authHeader, ConversationParameters parameters)

Create a new Conversation.

Parameters:

authHeader - The authentication header.
parameters - Parameters to create the conversation from.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleDeleteActivity

public CompletableFuture handleDeleteActivity(String authHeader, String conversationId, String activityId)

Deletes an existing activity.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
activityId - The activity Id.

Returns:

A CompletableFuture representing the result of the asynchronous operation.

handleDeleteConversationMember

public CompletableFuture handleDeleteConversationMember(String authHeader, String conversationId, String memberId)

Deletes a member from a conversation.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
memberId - Id of the member to delete from this conversation.

Returns:

A CompletableFuture representing the asynchronous operation.

handleGetActivityMembers

public CompletableFuture> handleGetActivityMembers(String authHeader, String conversationId, String activityId)

Enumerates the members of an activity.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
activityId - The activity Id.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleGetConversationMembers

public CompletableFuture> handleGetConversationMembers(String authHeader, String conversationId)

Enumerates the members of a conversation.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleGetConversationPagedMembers

public CompletableFuture handleGetConversationPagedMembers(String authHeader, String conversationId, Integer pageSize, String continuationToken)

Enumerates the members of a conversation one page at a time.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
pageSize - Suggested page size.
continuationToken - A continuation token.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleGetConversations

public CompletableFuture handleGetConversations(String authHeader, String conversationId, String continuationToken)

Lists the Conversations in which the bot has participated.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
continuationToken - A skip or continuation token.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleReplyToActivity

public CompletableFuture handleReplyToActivity(String authHeader, String conversationId, String activityId, Activity activity)

Sends a reply to an activity.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
activityId - The activity Id the reply is to.
activity - The activity to send.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleSendConversationHistory

public CompletableFuture handleSendConversationHistory(String authHeader, String conversationId, Transcript transcript)

Uploads the historic activities of the conversation.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
transcript - Transcript of activities.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleSendToConversation

public CompletableFuture handleSendToConversation(String authHeader, String conversationId, Activity activity)

Sends an activity to the end of a conversation.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
activity - The activity to send.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleUpdateActivity

public CompletableFuture handleUpdateActivity(String authHeader, String conversationId, String activityId, Activity activity)

Edits a previously sent existing activity.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
activityId - The activity Id to update.
activity - The replacement activity.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

handleUploadAttachment

public CompletableFuture handleUploadAttachment(String authHeader, String conversationId, AttachmentData attachmentUpload)

Stores data in a compliant store when dealing with enterprises.

Parameters:

authHeader - The authentication header.
conversationId - The conversation Id.
attachmentUpload - Attachment data.

Returns:

A {@link CompletableFuture{TResult}} representing the result of the asynchronous operation.

onCreateConversation

protected CompletableFuture onCreateConversation(ClaimsIdentity claimsIdentity, ConversationParameters parameters)

CreateConversation() API. Override this method to create a new Conversation. POST to this method with a * Bot being the bot creating the conversation * IsGroup set to true if this is not a direct message (default instanceof false) * Array containing the members to include in the conversation The return value is a ResourceResponse which contains a conversation D which is suitable for use in the message payload and REST API URIs. Most channels only support the semantics of bots initiating a direct message conversation. An example of how to do that would be: var resource = connector.getconversations().CreateConversation(new ConversationParameters(){ Bot = bot, members = new ChannelAccount[] { new ChannelAccount("user1") } ); connect.getConversations().OnSendToConversation(resource.getId(), new Activity() ... ) ; end.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
parameters - Parameters to create the conversation from.

Returns:

task for a conversation resource response.

onDeleteActivity

protected CompletableFuture onDeleteActivity(ClaimsIdentity claimsIdentity, String conversationId, String activityId)

OnDeleteActivity() API. Override this method to Delete an existing activity. Some channels allow you to delete an existing activity, and if successful this method will remove the specified activity.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.
activityId - activityId to delete.

Returns:

task for a resource response.

onDeleteConversationMember

protected CompletableFuture onDeleteConversationMember(ClaimsIdentity claimsIdentity, String conversationId, String memberId)

DeleteConversationMember() API for Skill. Override this method to deletes a member from a conversation. This REST API takes a ConversationId and a memberId (of type String) and removes that member from the conversation. If that member was the last member of the conversation, the conversation will also be deleted.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.
memberId - D of the member to delete from this conversation.

Returns:

task.

onGetActivityMembers

protected CompletableFuture> onGetActivityMembers(ClaimsIdentity claimsIdentity, String conversationId, String activityId)

OnGetActivityMembers() API. Override this method to enumerate the members of an activity. This REST API takes a ConversationId and a ActivityId, returning an array of ChannelAccount Objects representing the members of the particular activity in the conversation.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.
activityId - Activity D.

Returns:

task with result.

onGetConversationMembers

protected CompletableFuture> onGetConversationMembers(ClaimsIdentity claimsIdentity, String conversationId)

GetConversationMembers() API for Skill. Override this method to enumerate the members of a conversation. This REST API takes a ConversationId and returns an array of ChannelAccount Objects representing the members of the conversation.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.

Returns:

task for a response.

onGetConversationPagedMembers

protected CompletableFuture onGetConversationPagedMembers(ClaimsIdentity claimsIdentity, String conversationId, Integer pageSize, String continuationToken)

GetConversationPagedMembers() API for Skill. Override this method to enumerate the members of a conversation one page at a time. This REST API takes a ConversationId. Optionally a pageSize and/or continuationToken can be provided. It returns a PagedMembersResult, which contains an array of ChannelAccounts representing the members of the conversation and a continuation token that can be used to get more values. One page of ChannelAccounts records are returned with each call. The number of records in a page may vary between channels and calls. The pageSize parameter can be used as a suggestion. If there are no additional results the response will not contain a continuation token. If there are no members in the conversation the Members will be empty or not present in the response. A response to a request that has a continuation token from a prior request may rarely return members from a previous request.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.
pageSize - Suggested page size.
continuationToken - Continuation Token.

Returns:

task for a response.

onGetConversations

protected CompletableFuture onGetConversations(ClaimsIdentity claimsIdentity, String conversationId, String continuationToken)

OnGetConversations() API for Skill. Override this method to list the Conversations in which this bot has participated. GET from this method with a skip token The return value is a ConversationsResult, which contains an array of ConversationMembers and a skip token. If the skip token is not empty, then there are further values to be returned. Call this method again with the returned token to get more values. Each ConversationMembers Object contains the D of the conversation and an array of ChannelAccounts that describe the members of the conversation.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - conversationId.
continuationToken - skip or continuation token.

Returns:

task for ConversationsResult.

onReplyToActivity

protected CompletableFuture onReplyToActivity(ClaimsIdentity claimsIdentity, String conversationId, String activityId, Activity activity)

OnReplyToActivity() API. Override this method allows to reply to an Activity. This is slightly different from SendToConversation(). * SendToConversation(conversationId) - will append the activity to the end of the conversation according to the timestamp or semantics of the channel. * ReplyToActivity(conversationId,ActivityId) - adds the activity as a reply to another activity, if the channel supports it. If the channel does not support nested replies, ReplyToActivity falls back to SendToConversation. Use ReplyToActivity when replying to a specific activity in the conversation. Use SendToConversation in all other cases.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.
activityId - activityId the reply is to (OPTONAL).
activity - Activity to send.

Returns:

task for a resource response.

onSendConversationHistory

protected CompletableFuture onSendConversationHistory(ClaimsIdentity claimsIdentity, String conversationId, Transcript transcript)

SendConversationHistory() API for Skill. Override this method to this method allows you to upload the historic activities to the conversation. Sender must ensure that the historic activities have unique ids and appropriate timestamps. The ids are used by the client to deal with duplicate activities and the timestamps are used by the client to render the activities in the right order.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.
transcript - Transcript of activities.

Returns:

task for a resource response.

onSendToConversation

protected CompletableFuture onSendToConversation(ClaimsIdentity claimsIdentity, String conversationId, Activity activity)

SendToConversation() API for Skill. This method allows you to send an activity to the end of a conversation. This is slightly different from ReplyToActivity(). * SendToConversation(conversationId) - will append the activity to the end of the conversation according to the timestamp or semantics of the channel. * ReplyToActivity(conversationId,ActivityId) - adds the activity as a reply to another activity, if the channel supports it. If the channel does not support nested replies, ReplyToActivity falls back to SendToConversation. Use ReplyToActivity when replying to a specific activity in the conversation. Use SendToConversation in all other cases.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - conversationId.
activity - Activity to send.

Returns:

task for a resource response.

onUpdateActivity

protected CompletableFuture onUpdateActivity(ClaimsIdentity claimsIdentity, String conversationId, String activityId, Activity activity)

OnUpdateActivity() API. Override this method to edit a previously sent existing activity. Some channels allow you to edit an existing activity to reflect the new state of a bot conversation. For example, you can remove buttons after someone has clicked "Approve" button.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.
activityId - activityId to update.
activity - replacement Activity.

Returns:

task for a resource response.

onUploadAttachment

protected CompletableFuture onUploadAttachment(ClaimsIdentity claimsIdentity, String conversationId, AttachmentData attachmentUpload)

UploadAttachment() API. Override this method to store data in a compliant store when dealing with enterprises. The response is a ResourceResponse which contains an AttachmentId which is suitable for using with the attachments API.

Parameters:

claimsIdentity - claimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
conversationId - Conversation D.
attachmentUpload - Attachment data.

Returns:

task with result.

Applies to