Skip to content

Commit

Permalink
Merge branch 'main' into JonathanFingold-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanFingold committed Jun 16, 2021
2 parents 7e5a63f + 475c222 commit 3f2f85f
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public virtual async Task<SlackResponse> PostMessageAsync(NewSlackMessage messag
["channel"] = message.Channel,
["text"] = message.Text,
["thread_ts"] = message.ThreadTs,
["user"] = message.User,
};

if (message.Blocks != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace AdaptiveExpressions.Properties
/// </summary>
/// <remarks>String values are always interpreted as an expression, whether it has '=' prefix or not.</remarks>
[JsonConverter(typeof(NumberExpressionConverter))]
public class NumberExpression : ExpressionProperty<float>
public class NumberExpression : ExpressionProperty<double>
{
/// <summary>
/// Initializes a new instance of the <see cref="NumberExpression"/> class.
Expand All @@ -26,7 +26,7 @@ public NumberExpression()
/// Initializes a new instance of the <see cref="NumberExpression"/> class.
/// </summary>
/// <param name="value">value to use.</param>
public NumberExpression(float value)
public NumberExpression(double value)
: base(value)
{
}
Expand Down Expand Up @@ -72,7 +72,7 @@ public NumberExpression(JToken expressionOrValue)
/// </summary>
/// <param name="value">The floating point number number to convert.</param>
#pragma warning disable CA2225 // Operator overloads have named alternates
public static implicit operator NumberExpression(float value) => new NumberExpression(value);
public static implicit operator NumberExpression(double value) => new NumberExpression(value);

/// <summary>
/// Converts a string value to a NumberExpression instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ protected virtual Task<QnAMakerOptions> GetQnAMakerOptionsAsync(DialogContext dc
{
return Task.FromResult(new QnAMakerOptions
{
ScoreThreshold = this.Threshold.GetValue(dc.State),
ScoreThreshold = (float)this.Threshold.GetValue(dc.State),
StrictFilters = this.StrictFilters?.GetValue(dc.State)?.ToArray(),
Top = this.Top.GetValue(dc.State),
Context = new QnARequestContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public override async Task<RecognizerResult> RecognizeAsync(DialogContext dialog
new QnAMakerOptions
{
Context = Context?.GetValue(dialogContext.State),
ScoreThreshold = Threshold.GetValue(dialogContext.State),
ScoreThreshold = (float)Threshold.GetValue(dialogContext.State),
StrictFilters = filters.ToArray(),
Top = Top.GetValue(dialogContext.State),
QnAId = QnAId.GetValue(dialogContext.State),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ protected override Task<InputState> OnRecognizeInputAsync(DialogContext dc, Canc
// Try to parse value based on type
var text = results[0].Resolution["value"].ToString();

if (int.TryParse(text, out var intValue))
if (long.TryParse(text, out var intValue))
{
input = intValue;
}
else
{
if (float.TryParse(text, out var value))
if (double.TryParse(text, out var value))
{
input = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override void Initialize(IEnumerable<OnCondition> conditionals, bool eval
public override Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancellationToken)
{
OnCondition selection = null;
var lowestPriority = float.MaxValue;
var lowestPriority = double.MaxValue;
if (_evaluate)
{
for (var i = 0; i < _conditionals.Count; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public virtual Expression GetExpression()
/// </summary>
/// <param name="actionContext">Context to use for evaluation.</param>
/// <returns>Computed priority.</returns>
public float CurrentPriority(ActionContext actionContext)
public double CurrentPriority(ActionContext actionContext)
{
var (priority, error) = this.Priority.TryGetValue(actionContext.State);
if (error != null)
Expand Down
28 changes: 28 additions & 0 deletions libraries/Microsoft.Bot.Builder/BotAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,34 @@ public virtual Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, Act
throw new NotImplementedException();
}

/// <summary>
/// Creates a conversation on the specified channel.
/// </summary>
/// <param name="botAppId">TThe application ID of the bot.</param>
/// <param name="channelId">The ID for the channel.</param>
/// <param name="serviceUrl">The channel's service URL endpoint.</param>
/// <param name="audience">The audience for the connector.</param>
/// <param name="conversationParameters">The conversation information to use to
/// create the conversation.</param>
/// <param name="callback">The method to call for the resulting bot turn.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the work queued to execute.</returns>
/// <remarks>To start a conversation, your bot must know its account information
/// and the user's account information on that channel.
/// Most _channels only support initiating a direct message (non-group) conversation.
/// <para>The adapter attempts to create a new conversation on the channel, and
/// then sends a <c>conversationUpdate</c> activity through its middleware pipeline
/// to the <paramref name="callback"/> method.</para>
/// <para>If the conversation is established with the
/// specified users, the ID of the activity's <see cref="IActivity.Conversation"/>
/// will contain the ID of the new conversation.</para>
/// </remarks>
public virtual Task CreateConversationAsync(string botAppId, string channelId, string serviceUrl, string audience, ConversationParameters conversationParameters, BotCallbackHandler callback, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

/// <summary>
/// Creates a turn context and runs the middleware pipeline for an incoming TRUSTED activity.
/// </summary>
Expand Down
57 changes: 56 additions & 1 deletion libraries/Microsoft.Bot.Builder/CloudAdapterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,47 @@ public override Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, Ac
return ProcessProactiveAsync(claimsIdentity, continuationActivity, audience, callback, cancellationToken);
}

/// <inheritdoc/>
public override async Task CreateConversationAsync(string botAppId, string channelId, string serviceUrl, string audience, ConversationParameters conversationParameters, BotCallbackHandler callback, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(serviceUrl))
{
throw new ArgumentNullException(nameof(serviceUrl));
}

_ = conversationParameters ?? throw new ArgumentNullException(nameof(conversationParameters));
_ = callback ?? throw new ArgumentNullException(nameof(callback));

Logger.LogInformation($"CreateConversationAsync for channel: {channelId}");

// Create a ClaimsIdentity, to create the connector and for adding to the turn context.
var claimsIdentity = CreateClaimsIdentity(botAppId);
claimsIdentity.AddClaim(new Claim(AuthenticationConstants.ServiceUrlClaim, serviceUrl));

// Create the connector factory.
var connectorFactory = BotFrameworkAuthentication.CreateConnectorFactory(claimsIdentity);

// Create the connector client to use for outbound requests.
using (var connectorClient = await connectorFactory.CreateAsync(serviceUrl, audience, cancellationToken).ConfigureAwait(false))
{
// Make the actual create conversation call using the connector.
var createConversationResult = await connectorClient.Conversations.CreateConversationAsync(conversationParameters, cancellationToken).ConfigureAwait(false);

// Create the create activity to communicate the results to the application.
var createActivity = CreateCreateActivity(createConversationResult, channelId, serviceUrl, conversationParameters);

// Create a UserTokenClient instance for the application to use. (For example, in the OAuthPrompt.)
using (var userTokenClient = await BotFrameworkAuthentication.CreateUserTokenClientAsync(claimsIdentity, cancellationToken).ConfigureAwait(false))

// Create a turn context and run the pipeline.
using (var context = CreateTurnContext(createActivity, claimsIdentity, null, connectorClient, userTokenClient, callback, connectorFactory))
{
// Run the pipeline.
await RunPipelineAsync(context, callback, cancellationToken).ConfigureAwait(false);
}
}
}

/// <summary>
/// The implementation for continue conversation.
/// </summary>
Expand All @@ -205,7 +246,7 @@ protected async Task ProcessProactiveAsync(ClaimsIdentity claimsIdentity, Activi
{
Logger.LogInformation($"ProcessProactiveAsync for Conversation Id: {continuationActivity.Conversation.Id}");

// Create the connector factory and the inbound request, extracting parameters and then create a connector for outbound requests.
// Create the connector factory.
var connectorFactory = BotFrameworkAuthentication.CreateConnectorFactory(claimsIdentity);

// Create the connector client to use for outbound requests.
Expand Down Expand Up @@ -293,6 +334,20 @@ protected ClaimsIdentity CreateClaimsIdentity(string botAppId)
});
}

private Activity CreateCreateActivity(ConversationResourceResponse createConversationResult, string channelId, string serviceUrl, ConversationParameters conversationParameters)
{
// Create a conversation update activity to represent the result.
var activity = Activity.CreateEventActivity();
activity.Name = ActivityEventNames.CreateConversation;
activity.ChannelId = channelId;
activity.ServiceUrl = serviceUrl;
activity.Id = createConversationResult.ActivityId ?? Guid.NewGuid().ToString("n");
activity.Conversation = new ConversationAccount(id: createConversationResult.Id, tenantId: conversationParameters.TenantId);
activity.ChannelData = conversationParameters.ChannelData;
activity.Recipient = conversationParameters.Bot;
return (Activity)activity;
}

private TurnContext CreateTurnContext(Activity activity, ClaimsIdentity claimsIdentity, string oauthScope, IConnectorClient connectorClient, UserTokenClient userTokenClient, BotCallbackHandler callback, ConnectorFactory connectorFactory)
{
var turnContext = new TurnContext(this, activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public void ActivityToSlackShouldReturnMessage()
public void ActivityToSlackShouldReturnMessageFromChannelData()
{
const string messageText = "Hello from message";
const string ephemeralValue = "testEphemeral";
const string channelId = "channelId";
const string userId = "testRecipientId";

var activity = new Activity
{
Expand All @@ -62,14 +65,19 @@ public void ActivityToSlackShouldReturnMessageFromChannelData()
ChannelData = new NewSlackMessage
{
Text = messageText,
Ephemeral = "testEphemeral"
Ephemeral = ephemeralValue,
Channel = channelId,
User = userId,
},
Conversation = new ConversationAccount(id: "testId"),
};

var message = SlackHelper.ActivityToSlack(activity);

Assert.Equal(messageText, message.Text);
Assert.Equal(ephemeralValue, message.Ephemeral);
Assert.Equal(channelId, message.Channel);
Assert.Equal(userId, message.User);
}

[Fact]
Expand Down
14 changes: 7 additions & 7 deletions tests/AdaptiveExpressions.Tests/ExpressionPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void ExpressionPropertyTests_TestImplicitCasts()

Assert.Equal("test", test.Str.TryGetValue(data).Value);
Assert.Equal(13, test.Int.TryGetValue(data).Value);
Assert.Equal(3.14F, test.Number.TryGetValue(data).Value);
Assert.Equal(3.14D, test.Number.TryGetValue(data).Value);
Assert.Equal(TestEnum.Two, test.Enm.TryGetValue(data).Value);
Assert.True(test.Bool.TryGetValue(data).Value);
Assert.Equal("one", test.Strings.TryGetValue(data).Value[0]);
Expand All @@ -247,7 +247,7 @@ public void ExpressionPropertyTests_TestImplicitCasts()

Assert.Equal("test2", test.Str.TryGetValue(data).Value);
Assert.Equal(113, test.Int.TryGetValue(data).Value);
Assert.Equal(13.14F, test.Number.TryGetValue(data).Value);
Assert.Equal(13.14D, test.Number.TryGetValue(data).Value);
Assert.Equal(TestEnum.Three, test.Enm.TryGetValue(data).Value);
Assert.True(test.Bool.TryGetValue(data).Value);
Assert.Equal("a", test.Strings.TryGetValue(data).Value[0]);
Expand All @@ -259,7 +259,7 @@ public void ExpressionPropertyTests_TestImplicitCasts()
var test2 = JsonConvert.DeserializeObject<ImplicitCastTest>(json, settings: settings);
Assert.Equal("test2", test2.Str.TryGetValue(data).Value);
Assert.Equal(113, test2.Int.TryGetValue(data).Value);
Assert.Equal(13.14F, test2.Number.TryGetValue(data).Value);
Assert.Equal(13.14D, test2.Number.TryGetValue(data).Value);
Assert.Equal(TestEnum.Three, test2.Enm.TryGetValue(data).Value);
Assert.True(test2.Bool.TryGetValue(data).Value);
Assert.Equal("a", test2.Strings.TryGetValue(data).Value[0]);
Expand All @@ -275,7 +275,7 @@ public void ExpressionPropertyTests_TestImplicitCasts()

Assert.Equal("test2", test.Str.TryGetValue(data).Value);
Assert.Equal(113, test.Int.TryGetValue(data).Value);
Assert.Equal(13.14F, test.Number.TryGetValue(data).Value);
Assert.Equal(13.14D, test.Number.TryGetValue(data).Value);
Assert.Equal(TestEnum.Three, test.Enm.TryGetValue(data).Value);
Assert.True(test.Bool.TryGetValue(data).Value);

Expand All @@ -288,7 +288,7 @@ public void ExpressionPropertyTests_TestImplicitCasts()

Assert.Equal("test2", test.Str.TryGetValue(data).Value);
Assert.Equal(113, test.Int.TryGetValue(data).Value);
Assert.Equal(13.14F, test.Number.TryGetValue(data).Value);
Assert.Equal(13.14D, test.Number.TryGetValue(data).Value);
Assert.Equal(TestEnum.Three, test.Enm.TryGetValue(data).Value);
Assert.True(test.Bool.TryGetValue(data).Value);

Expand All @@ -301,7 +301,7 @@ public void ExpressionPropertyTests_TestImplicitCasts()

Assert.Equal("test2", test.Str.TryGetValue(data).Value);
Assert.Equal(113, test.Int.TryGetValue(data).Value);
Assert.Equal(13.14F, test.Number.TryGetValue(data).Value);
Assert.Equal(13.14D, test.Number.TryGetValue(data).Value);
Assert.Equal(TestEnum.Three, test.Enm.TryGetValue(data).Value);
Assert.True(test.Bool.TryGetValue(data).Value);

Expand Down Expand Up @@ -545,7 +545,7 @@ public void ExpressionPropertyTests_IntExpression()
[Fact]
public void ExpressionPropertyTests_FloatExpression()
{
TestNumberExpression<NumberExpression, float>(new NumberExpression(), 3.14F);
TestNumberExpression<NumberExpression, double>(new NumberExpression(), 3.14D);
}

private void TestNumberExpression<TExpression, TValue>(TExpression val, TValue expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ public async Task Action_NumberInput()
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer);
}

[Fact]
public async Task Action_NumberInput_LargeNumber()
{
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer);
}

[Fact]
public async Task Action_NumberInputWithDefaultValue()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"id": "planningTest",
"triggers": [
{
"$kind": "Microsoft.OnUnknownIntent",
"actions": [
{
"$kind": "Microsoft.NumberInput",
"property": "user.test.Amount",
"outputFormat": "=int(this.value)",
"prompt": "Please enter your lucky number."
},
{
"$kind": "Microsoft.SendActivity",
"activity": "I have your lucky number as ${user.test.Amount}."
}
]
}
],
"defaultResultProperty": "dialog.result"
},
"script": [
{
"$kind": "Microsoft.Test.UserSays",
"text": "hi"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "Please enter your lucky number."
},
{
"$kind": "Microsoft.Test.UserSays",
"text": "8144331287 "
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "I have your lucky number as 8144331287."
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SchemaTestsFixture()
File.Delete(schemaPath);

// Merge all schema files,
var mergeCommand = $"/C bf dialog:merge ../../libraries/**/*.schema ../../libraries/**/*.uischema ../**/*.schema !../**/testbot.schema -o {schemaPath}";
var mergeCommand = $"/C bf dialog:merge ../../libraries/**/*.schema ../../libraries/**/*.uischema ../**/*.schema !../**/testbot.schema -o \"{schemaPath}\"";
var error = RunCommand(mergeCommand);

// Check if there were any errors or if the new schema file has changed.
Expand Down
Loading

0 comments on commit 3f2f85f

Please sign in to comment.