Skip to content

Commit fd47104

Browse files
rvinothrajendrangarypretty
authored andcommitted
Custom action EmailInput to bot framework composer (#353)
1 parent 02db198 commit fd47104

6 files changed

Lines changed: 157 additions & 2 deletions

File tree

Bot.Builder.Community.sln

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Builder.Community.Adapt
123123
EndProject
124124
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Builder.Community.Adapters.Infobip.WhatsApp.Tests", "tests\Bot.Builder.Community.Adapters.Infobip.WhatsApp.Tests\Bot.Builder.Community.Adapters.Infobip.WhatsApp.Tests.csproj", "{E8FAA9DA-D193-466D-896C-D053AC5CD154}"
125125
EndProject
126+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Builder.Community.Dialogs.CustomInput", "libraries\Bot.Builder.Community.Dialogs.CustomAction\Bot.Builder.Community.Dialogs.CustomInput.csproj", "{D586DAC3-D231-43B8-82F4-D2F225AC9668}"
127+
EndProject
126128
Global
127129
GlobalSection(SolutionConfigurationPlatforms) = preSolution
128130
Debug - NuGet Packages|Any CPU = Debug - NuGet Packages|Any CPU
@@ -513,6 +515,14 @@ Global
513515
{E8FAA9DA-D193-466D-896C-D053AC5CD154}.Documentation|Any CPU.Build.0 = Debug|Any CPU
514516
{E8FAA9DA-D193-466D-896C-D053AC5CD154}.Release|Any CPU.ActiveCfg = Release|Any CPU
515517
{E8FAA9DA-D193-466D-896C-D053AC5CD154}.Release|Any CPU.Build.0 = Release|Any CPU
518+
{D586DAC3-D231-43B8-82F4-D2F225AC9668}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug|Any CPU
519+
{D586DAC3-D231-43B8-82F4-D2F225AC9668}.Debug - NuGet Packages|Any CPU.Build.0 = Debug|Any CPU
520+
{D586DAC3-D231-43B8-82F4-D2F225AC9668}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
521+
{D586DAC3-D231-43B8-82F4-D2F225AC9668}.Debug|Any CPU.Build.0 = Debug|Any CPU
522+
{D586DAC3-D231-43B8-82F4-D2F225AC9668}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
523+
{D586DAC3-D231-43B8-82F4-D2F225AC9668}.Documentation|Any CPU.Build.0 = Debug|Any CPU
524+
{D586DAC3-D231-43B8-82F4-D2F225AC9668}.Release|Any CPU.ActiveCfg = Release|Any CPU
525+
{D586DAC3-D231-43B8-82F4-D2F225AC9668}.Release|Any CPU.Build.0 = Release|Any CPU
516526
EndGlobalSection
517527
GlobalSection(SolutionProperties) = preSolution
518528
HideSolutionNode = FALSE
@@ -555,8 +565,6 @@ Global
555565
{895AE009-325A-4BDF-B0F7-7F5275744D22} = {840D4038-9AB8-4750-9FFE-365386CE47E2}
556566
{DA1A84A1-D921-412F-A855-93FC9A525D27} = {BF310E8A-8DA1-441F-90E9-DE0E66553048}
557567
{7856219A-3537-4F81-86A8-4CB020BD2B9A} = {BF310E8A-8DA1-441F-90E9-DE0E66553048}
558-
{DA1A84A1-D921-412F-A855-93FC9A525D27} = {BF310E8A-8DA1-441F-90E9-DE0E66553048}
559-
{7856219A-3537-4F81-86A8-4CB020BD2B9A} = {BF310E8A-8DA1-441F-90E9-DE0E66553048}
560568
{58EF2CAF-5B27-476B-A9C7-BB6A8D8B470B} = {BF310E8A-8DA1-441F-90E9-DE0E66553048}
561569
{22EBD054-1CBC-4832-9D90-4F243570CB54} = {BF310E8A-8DA1-441F-90E9-DE0E66553048}
562570
{87220934-70D0-4BE7-8ED3-C403281CCCFD} = {BF310E8A-8DA1-441F-90E9-DE0E66553048}
@@ -573,6 +581,7 @@ Global
573581
{DE1D7A6A-8018-4375-8118-98A72EE5505A} = {840D4038-9AB8-4750-9FFE-365386CE47E2}
574582
{B9347740-E245-4B13-8BA8-222C27522E82} = {840D4038-9AB8-4750-9FFE-365386CE47E2}
575583
{E8FAA9DA-D193-466D-896C-D053AC5CD154} = {840D4038-9AB8-4750-9FFE-365386CE47E2}
584+
{D586DAC3-D231-43B8-82F4-D2F225AC9668} = {08759E28-8592-4EBA-9A07-19A5BED3FB0C}
576585
EndGlobalSection
577586
GlobalSection(ExtensibilityGlobals) = postSolution
578587
SolutionGuid = {9FE3B75E-BA2B-45BC-BBF0-DDA8BA10C4F0}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<Description>A collection of custom input for Bot Framework Composer</Description>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive" Version="4.11.0" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.Generic;
2+
using Bot.Builder.Community.Dialogs.CustomInput.Input;
3+
using Microsoft.Bot.Builder;
4+
using Microsoft.Bot.Builder.Dialogs.Debugging;
5+
using Microsoft.Bot.Builder.Dialogs.Declarative;
6+
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;
7+
using Newtonsoft.Json;
8+
9+
namespace Bot.Builder.Community.Dialogs.CustomInput
10+
{
11+
public class DialogCustomInputComponentRegistration : ComponentRegistration,IComponentDeclarativeTypes
12+
{
13+
public IEnumerable<DeclarativeType> GetDeclarativeTypes(ResourceExplorer resourceExplorer)
14+
{
15+
yield return new DeclarativeType<EmailInput>(EmailInput.Kind);
16+
}
17+
18+
public IEnumerable<JsonConverter> GetConverters(ResourceExplorer resourceExplorer, SourceContext sourceContext)
19+
{
20+
yield break;
21+
}
22+
}
23+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System.Runtime.CompilerServices;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using AdaptiveExpressions.Properties;
5+
using Microsoft.Bot.Builder;
6+
using Microsoft.Bot.Builder.Dialogs;
7+
using Microsoft.Bot.Builder.Dialogs.Adaptive.Input;
8+
using Microsoft.Bot.Builder.Dialogs.Adaptive.Templates;
9+
using Microsoft.Bot.Schema;
10+
using Microsoft.Recognizers.Text.Sequence;
11+
using Newtonsoft.Json;
12+
using static Microsoft.Recognizers.Text.Culture;
13+
14+
namespace Bot.Builder.Community.Dialogs.CustomInput.Input
15+
{
16+
public class EmailInput : InputDialog
17+
{
18+
[JsonProperty("$Kind")]
19+
public const string Kind = "EmailInput";
20+
21+
[JsonProperty("defaultLocale")]
22+
public StringExpression DefaultLocale { get; set; }
23+
24+
[JsonProperty("resultProperty")]
25+
public StringExpression ResultProperty { get; set; }
26+
27+
[JsonConstructor]
28+
public EmailInput([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
29+
{
30+
this.RegisterSourceLocation(sourceFilePath, sourceLineNumber);
31+
}
32+
33+
protected override Task<IActivity> OnRenderPromptAsync(DialogContext dc, InputState state,
34+
CancellationToken cancellationToken = new CancellationToken())
35+
{
36+
if (this.Prompt == null)
37+
{
38+
this.Prompt = new StaticActivityTemplate(MessageFactory.Text("Prompt for a email"));
39+
}
40+
return base.OnRenderPromptAsync(dc, state, cancellationToken);
41+
}
42+
43+
protected override Task<InputState> OnRecognizeInputAsync(DialogContext dc, CancellationToken cancellationToken)
44+
{
45+
var validateText = dc.State.GetValue<object>(VALUE_PROPERTY);
46+
47+
if (!(validateText is string strEmailText))
48+
{
49+
return Task.FromResult(InputState.Invalid);
50+
}
51+
52+
var culture = GetCulture(dc);
53+
54+
var recognizeEmail = SequenceRecognizer.RecognizeEmail(strEmailText, culture);
55+
56+
if (recognizeEmail == null || recognizeEmail.Count <= 0)
57+
{
58+
return Task.FromResult(InputState.Unrecognized);
59+
}
60+
61+
var result = recognizeEmail[0].Resolution["value"].ToString();
62+
dc.State.SetValue(this.ResultProperty.GetValue(dc.State), result);
63+
64+
return Task.FromResult(InputState.Valid);
65+
66+
}
67+
68+
private string GetCulture(DialogContext dc)
69+
{
70+
if (!string.IsNullOrEmpty(dc.Context.Activity.Locale))
71+
{
72+
return dc.Context.Activity.Locale;
73+
}
74+
75+
return this.DefaultLocale != null ? this.DefaultLocale.GetValue(dc.State) : English;
76+
}
77+
}
78+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema",
3+
"$role": [ "implements(Microsoft.IDialog)", "extends(Microsoft.InputDialog)" ],
4+
"title": "Email",
5+
"description": "This will return the result of Email address",
6+
"type": "object",
7+
"properties": {
8+
"defaultLocale": {
9+
"$ref": "schema:#/definitions/stringExpression",
10+
"description": "Value from callers memory to use as localization",
11+
"title": "DefaultLocale"
12+
},
13+
"resultProperty": {
14+
"$ref": "schema:#/definitions/stringExpression",
15+
"description": "Value from callers memory to store the result",
16+
"title": "Result"
17+
}
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://schemas.botframework.com/schemas/ui/v1.0/ui.schema",
3+
"form": {
4+
"label": "Prompt for a Email",
5+
"subtitle": "Email Input(Bot Builder Community)",
6+
"properties": {
7+
"property": {
8+
"intellisenseScopes": [
9+
"variable-scopes"
10+
]
11+
}
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)