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.
# Adding action model to showcase advanced usage options
- Loading branch information
maurok
committed
Jun 1, 2017
1 parent
0778c0d
commit eb63e58
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
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 - default JSON model does not have it | ||
|
||
// 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 | ||
|
||
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