Skip to content

Commit

Permalink
Support bot config invoke type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ying Du committed May 17, 2023
1 parent bb6a077 commit 7215218
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 0 deletions.
32 changes: 32 additions & 0 deletions libraries/Microsoft.Bot.Builder/Teams/TeamsActivityHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ protected override async Task<InvokeResponse> OnInvokeActivityAsync(ITurnContext
case "tab/submit":
return CreateInvokeResponse(await OnTeamsTabSubmitAsync(turnContext, SafeCast<TabSubmit>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));

case "config/fetch":
return CreateInvokeResponse(await OnTeamsConfigFetchAsync(turnContext, turnContext.Activity.Value as JObject, cancellationToken).ConfigureAwait(false));

case "config/submit":
return CreateInvokeResponse(await OnTeamsConfigSubmitAsync(turnContext, turnContext.Activity.Value as JObject, cancellationToken).ConfigureAwait(false));

default:
return await base.OnInvokeActivityAsync(turnContext, cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -431,6 +437,32 @@ protected virtual Task<TabResponse> OnTeamsTabSubmitAsync(ITurnContext<IInvokeAc
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}

/// <summary>
/// Override this in a derived class to provide logic for when a config is fetched.
/// </summary>
/// <param name="turnContext">A strongly-typed context object for this turn.</param>
/// <param name="configData">The config fetch invoke request value payload.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A Config Response for the request.</returns>
protected virtual Task<InvokeResponseBase> OnTeamsConfigFetchAsync(ITurnContext<IInvokeActivity> turnContext, JObject configData, CancellationToken cancellationToken)
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}

/// <summary>
/// Override this in a derived class to provide logic for when a config is fetched.
/// </summary>
/// <param name="turnContext">A strongly-typed context object for this turn.</param>
/// <param name="configData">The config fetch invoke request value payload.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A Config Response for the request.</returns>
protected virtual Task<InvokeResponseBase> OnTeamsConfigSubmitAsync(ITurnContext<IInvokeActivity> turnContext, JObject configData, CancellationToken cancellationToken)
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}

/// <summary>
/// Invoked when a conversation update activity is received from the channel.
/// Conversation update activities are useful when it comes to responding to users being added to or removed from the channel.
Expand Down
37 changes: 37 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/BotConfigAuth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Newtonsoft.Json;

namespace Microsoft.Bot.Schema.Teams
{
/// <summary>
/// Specifies bot config authe, including type and suggestedActions.
/// </summary>
public class BotConfigAuth
{
/// <summary>
/// Initializes a new instance of the <see cref="BotConfigAuth"/> class.
/// </summary>
public BotConfigAuth()
{
}

/// <summary>
/// Gets or sets type of bot config auth.
/// </summary>
/// <value>
/// The type of bot config auth.
/// </value>
[JsonProperty(PropertyName = "type")]
public string Type { get; set; } = "auth";

/// <summary>
/// Gets or sets suggested actions.
/// </summary>
/// <value>
/// The suggested actions of bot config auth.
/// </value>
[JsonProperty(PropertyName = "suggestedActions")]
public SuggestedActions SuggestedActions { get; set; }
}
}
18 changes: 18 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/ConfigAuthResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Bot.Schema.Teams
{
/// <summary>
/// Envelope for Config Auth Response.
/// </summary>
public partial class ConfigAuthResponse : ConfigResponse<BotConfigAuth>
{
/// <summary>
/// Initializes a new instance of the <see cref="ConfigAuthResponse"/> class.
/// </summary>
public ConfigAuthResponse()
{
}
}
}
33 changes: 33 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/ConfigResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Bot.Schema.Teams
{
using System;
using Newtonsoft.Json;

/// <summary>
/// Envelope for Config Response Payload.
/// </summary>
/// <typeparam name="T">The first generic type parameter.</typeparam>.
public partial class ConfigResponse<T> : InvokeResponseBase
{
/// <summary>
/// Initializes a new instance of the <see cref="ConfigResponse{T}"/> class.
/// </summary>
public ConfigResponse()
{
ResponseType = "config";
}

/// <summary>
/// Gets or sets the response to the config message.
/// Possible values for the config type include: 'auth'or 'task'.
/// </summary>
/// <value>
/// Response to a config request.
/// </value>
[JsonProperty(PropertyName = "config")]
public T Config { get; set; }
}
}
18 changes: 18 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/ConfigTaskResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Bot.Schema.Teams
{
/// <summary>
/// Envelope for Config Task Response.
/// </summary>
public partial class ConfigTaskResponse : ConfigResponse<TaskModuleResponseBase>
{
/// <summary>
/// Initializes a new instance of the <see cref="ConfigTaskResponse"/> class.
/// </summary>
public ConfigTaskResponse()
{
}
}
}
38 changes: 38 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/InvokeResponseBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace Microsoft.Bot.Schema.Teams
{
/// <summary>
/// Specifies Invoke response base including response type.
/// </summary>
public class InvokeResponseBase
{
/// <summary>
/// Initializes a new instance of the <see cref="InvokeResponseBase"/> class.
/// </summary>
protected InvokeResponseBase()
{
}

/// <summary>
/// Gets or sets response type invoke request.
/// </summary>
/// <value>
/// Invoke request response type.
/// </value>
[JsonProperty("responseType")]
public string ResponseType { get; set; }

/// <summary>
/// Gets or sets response cache Info.
/// </summary>
/// <value>
/// Value of cache info.
/// </value>
[JsonProperty(PropertyName = "cacheInfo")]
public CacheInfo CacheInfo { get; set; }
}
}

0 comments on commit 7215218

Please sign in to comment.