-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 #1326 from Microsoft/kaiqb/suggestedActions
Updated SuggestedActions, AdaptiveCards, and Welcome User sample
- Loading branch information
Showing
18 changed files
with
236 additions
and
464 deletions.
There are no files selected for viewing
File renamed without changes.
33 changes: 0 additions & 33 deletions
33
samples/csharp_dotnetcore/03.welcome-user/DeploymentScripts/MSbotClone/bot.recipe
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
samples/csharp_dotnetcore/03.welcome-user/welcome-user.bot
This file was deleted.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
samples/csharp_dotnetcore/08.suggested-actions/AdapterWithErrorHandler.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,24 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Bot.Builder.Integration.AspNet.Core; | ||
using Microsoft.Bot.Connector.Authentication; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
public class AdapterWithErrorHandler : BotFrameworkHttpAdapter | ||
{ | ||
public AdapterWithErrorHandler(ICredentialProvider credentialProvider, ILogger<BotFrameworkHttpAdapter> logger) | ||
: base(credentialProvider) | ||
{ | ||
// Enable logging at the adapter level using OnTurnError. | ||
OnTurnError = async (turnContext, exception) => | ||
{ | ||
logger.LogError($"Exception caught : {exception}"); | ||
await turnContext.SendActivityAsync("Sorry, it looks like something went wrong."); | ||
await turnContext.SendActivityAsync("To run this sample make sure you have the QnA model deployed."); | ||
}; | ||
} | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
samples/csharp_dotnetcore/08.suggested-actions/BotBuilder.ruleset
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
samples/csharp_dotnetcore/08.suggested-actions/Bots/SuggestedActionsBot.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,102 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Schema; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
// This bot will respond to the user's input with suggested actions. | ||
// Suggested actions enable your bot to present buttons that the user | ||
// can tap to provide input. | ||
public class SuggestedActionsBot : ActivityHandler | ||
{ | ||
public const string WelcomeText = @"This bot will introduce you to suggestedActions. | ||
Please answer the question:"; | ||
|
||
|
||
protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
// Send a welcome message to the user and tell them what actions they may perform to use this bot | ||
await SendWelcomeMessageAsync(turnContext, cancellationToken); | ||
} | ||
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
|
||
// Extract the text from the message activity the user sent. | ||
var text = turnContext.Activity.Text.ToLowerInvariant(); | ||
|
||
// Take the input from the user and create the appropriate response. | ||
var responseText = ProcessInput(text); | ||
|
||
// Respond to the user. | ||
await turnContext.SendActivityAsync(responseText, cancellationToken: cancellationToken); | ||
|
||
await SendSuggestedActionsAsync(turnContext, cancellationToken); | ||
} | ||
private static async Task SendWelcomeMessageAsync(ITurnContext turnContext, CancellationToken cancellationToken) | ||
{ | ||
foreach (var member in turnContext.Activity.MembersAdded) | ||
{ | ||
if (member.Id != turnContext.Activity.Recipient.Id) | ||
{ | ||
await turnContext.SendActivityAsync( | ||
$"Welcome to SuggestedActionsBot {member.Name}. {WelcomeText}", | ||
cancellationToken: cancellationToken); | ||
await SendSuggestedActionsAsync(turnContext, cancellationToken); | ||
} | ||
} | ||
} | ||
|
||
private static string ProcessInput(string text) | ||
{ | ||
const string colorText = "is the best color, I agree."; | ||
switch (text) | ||
{ | ||
case "red": | ||
{ | ||
return $"Red {colorText}"; | ||
} | ||
|
||
case "yellow": | ||
{ | ||
return $"Yellow {colorText}"; | ||
} | ||
|
||
case "blue": | ||
{ | ||
return $"Blue {colorText}"; | ||
} | ||
|
||
default: | ||
{ | ||
return "Please select a color from the suggested action choices"; | ||
} | ||
} | ||
} | ||
|
||
// Creates and sends an activity with suggested actions to the user. When the user | ||
/// clicks one of the buttons the text value from the "CardAction" will be | ||
/// displayed in the channel just as if the user entered the text. There are multiple | ||
/// "ActionTypes" that may be used for different situations. | ||
private static async Task SendSuggestedActionsAsync(ITurnContext turnContext, CancellationToken cancellationToken) | ||
{ | ||
var reply = turnContext.Activity.CreateReply("What is your favorite color?"); | ||
reply.SuggestedActions = new SuggestedActions() | ||
{ | ||
Actions = new List<CardAction>() | ||
{ | ||
new CardAction() { Title = "Red", Type = ActionTypes.ImBack, Value = "Red" }, | ||
new CardAction() { Title = "Yellow", Type = ActionTypes.ImBack, Value = "Yellow" }, | ||
new CardAction() { Title = "Blue", Type = ActionTypes.ImBack, Value = "Blue" }, | ||
}, | ||
}; | ||
await turnContext.SendActivityAsync(reply, cancellationToken); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
samples/csharp_dotnetcore/08.suggested-actions/ConfigurationCredentialProvider.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,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Bot.Connector.Authentication; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
public class ConfigurationCredentialProvider : SimpleCredentialProvider | ||
{ | ||
public ConfigurationCredentialProvider(IConfiguration configuration) | ||
: base(configuration["MicrosoftAppId"], configuration["MicrosoftAppPassword"]) | ||
{ | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
samples/csharp_dotnetcore/08.suggested-actions/Controllers/BotController.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,35 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.Integration.AspNet.Core; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot | ||
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be | ||
// achieved by specifying a more specific type for the bot constructor argument. | ||
[Route("api/messages")] | ||
[ApiController] | ||
public class BotController : ControllerBase | ||
{ | ||
private readonly IBotFrameworkHttpAdapter _adapter; | ||
private readonly IBot _bot; | ||
|
||
public BotController(IBotFrameworkHttpAdapter adapter, IBot bot) | ||
{ | ||
_adapter = adapter; | ||
_bot = bot; | ||
} | ||
|
||
[HttpPost] | ||
public async Task PostAsync() | ||
{ | ||
// Delegate the processing of the HTTP POST to the adapter. | ||
// The adapter will invoke the bot. | ||
await _adapter.ProcessAsync(Request, Response, _bot); | ||
} | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
samples/csharp_dotnetcore/08.suggested-actions/DeploymentScripts/MsbotClone/bot.recipe
This file was deleted.
Oops, something went wrong.
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.