forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
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 microsoft#140 from southworkscom/csharp-luis-actio…
…ns-assignentitiesfix [C# - Luis Action Binding] Fix to issue microsoft#139 & improvements
- Loading branch information
Showing
4 changed files
with
116 additions
and
7 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
58 changes: 58 additions & 0 deletions
58
CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/Advanced/AlternativesAction.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,58 @@ | ||
namespace LuisActions.Samples | ||
{ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Threading.Tasks; | ||
using Microsoft.Cognitive.LUIS.ActionBinding; | ||
using Newtonsoft.Json; | ||
|
||
// This sample were added to showcase support to Custom List Entities | ||
|
||
// Refer to 'List Entities' @ https://docs.microsoft.com/en-us/azure/cognitive-services/luis/add-entities | ||
|
||
// You can create your own model with an 'AlternativeChoose' intent with utterances | ||
// having a 'List Entity' called 'Alternatives' with the canonical forms defined by the | ||
// 'Alternative' enum - or just can simply create your custom list entity, | ||
// intent and update the intent binding here and custom name/type at fields | ||
|
||
// Note: The provided LUIS app @ LUIS_MODEL.json does not have an intent related to it | ||
|
||
public enum Alternative | ||
{ | ||
// default (ie. empty choice) | ||
None = 0, | ||
|
||
DomainOption1 = 11, | ||
DomainOption2 = 12, | ||
DomainOption3 = 13, | ||
|
||
ExternalOption1 = 101, | ||
ExternalOption2 = 102 | ||
} | ||
|
||
public class RequiredEnumAttribute : ValidationAttribute | ||
{ | ||
public override bool IsValid(object value) | ||
{ | ||
return (int)value > 0; | ||
} | ||
} | ||
|
||
[Serializable] | ||
[LuisActionBinding("AlternativeChoose", FriendlyName = "Alternatives Choosing Model Sample")] | ||
public class AlternativesAction : BaseLuisAction | ||
{ | ||
[RequiredEnum(ErrorMessage = "Please provide an alternative")] | ||
[LuisActionBindingParam(CustomType = "Alternatives", Order = 1)] | ||
public Alternative FirstAlternative { get; set; } | ||
|
||
[Required(ErrorMessage = "Please provide one or more alternatives")] | ||
[LuisActionBindingParam(CustomType = "Alternatives", Order = 2)] | ||
public Alternative[] SecondaryAlternatives { get; set; } | ||
|
||
public override Task<object> FulfillAsync() | ||
{ | ||
return Task.FromResult((object)JsonConvert.SerializeObject(this)); | ||
} | ||
} | ||
} |
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