This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3829 from southworks/external/feature/southworks/…
…deprecation-plan/fix-c#-template-parity [C#][VA/Skill] Replicate changes of Samples to Templates
- Loading branch information
Showing
18 changed files
with
228 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
templates/csharp/VA/VA/Extensions/InvokeActivityExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using AdaptiveExpressions; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using $safeprojectname$.Models; | ||
|
||
namespace $safeprojectname$.Extensions | ||
{ | ||
/// <summary> | ||
/// Extension class for getting SkillId from Activity. | ||
/// </summary> | ||
public static class InvokeActivityExtensions | ||
{ | ||
// Fetches skillId from CardAction data if present | ||
public static string GetSkillId(this IInvokeActivity activity, ILogger logger) | ||
{ | ||
if (activity == null) | ||
{ | ||
logger.Log(LogLevel.Error, "activity is null from TaskModule"); | ||
throw new ArgumentNullException(nameof(activity)); | ||
} | ||
|
||
if (activity.Value == null) | ||
{ | ||
logger.Log(LogLevel.Error, "activity.Value is null from TaskModule"); | ||
throw new ArgumentException("activity.Value is null.", nameof(activity)); | ||
} | ||
|
||
// GetSkillId from Activity Value | ||
var data = JObject.Parse(activity.Value.ToString()).SelectToken("data.data")?.ToObject<SkillCardActionData>(); | ||
return data.SkillId ?? throw new ArgumentException("SkillId in TaskModule is null", nameof(SkillCardActionData)); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
templates/csharp/VA/VA/Extensions/InvokeResponseExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Schema.Teams; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace $safeprojectname$.Extensions | ||
{ | ||
/// <summary> | ||
/// InvokeResposneHandler class for returning TaskModuleResponse from InvokeResponse | ||
/// </summary> | ||
public static class InvokeResponseExtensions | ||
{ | ||
// Converts "InvokeResponse" sent by SkillHttpClient to "TaskModuleResponse" | ||
public static TaskModuleResponse GetTaskModuleResponse(this InvokeResponse invokeResponse) | ||
{ | ||
if (invokeResponse == null) | ||
{ | ||
throw new ArgumentNullException(nameof(invokeResponse)); | ||
} | ||
|
||
if (invokeResponse.Body != null) | ||
{ | ||
return new TaskModuleResponse() | ||
{ | ||
Task = GetTask(invokeResponse.Body), | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static TaskModuleResponseBase GetTask(object invokeResponseBody) | ||
{ | ||
var responseBody = JObject.FromObject(invokeResponseBody); | ||
var task = responseBody.GetValue("task"); | ||
string taskType = task.SelectToken("type")?.Value<string>(); | ||
|
||
return taskType switch | ||
{ | ||
"continue" => new TaskModuleContinueResponse() | ||
{ | ||
Type = taskType, | ||
Value = task.SelectToken("value").ToObject<TaskModuleTaskInfo>(), | ||
}, | ||
"message" => new TaskModuleMessageResponse() | ||
{ | ||
Type = taskType, | ||
Value = task.SelectToken("value").ToString(), | ||
}, | ||
_ => null, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace $safeprojectname$.Models | ||
{ | ||
/// <summary> | ||
/// Skill Card action data should contain skillName parameter | ||
/// This class is used to deserialize it and get skillName. | ||
/// </summary> | ||
/// <value> | ||
/// SkillName. | ||
/// </value> | ||
public class SkillCardActionData | ||
{ | ||
[JsonProperty("SkillId")] | ||
public string SkillId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.