-
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.
Added sample for FIC Echo Bot (#4019)
- Loading branch information
1 parent
a3657d4
commit 75fccfb
Showing
22 changed files
with
1,719 additions
and
8 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
29 changes: 29 additions & 0 deletions
29
samples/csharp_dotnetcore/86.bot-authentication-fic/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,29 @@ | ||
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v4.22.0 | ||
|
||
using Microsoft.Bot.Builder.Integration.AspNet.Core; | ||
using Microsoft.Bot.Builder.TraceExtensions; | ||
using Microsoft.Bot.Connector.Authentication; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
public class AdapterWithErrorHandler : CloudAdapter | ||
{ | ||
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<IBotFrameworkHttpAdapter> logger) | ||
: base(auth, logger) | ||
{ | ||
OnTurnError = async (turnContext, exception) => | ||
{ | ||
// Log any leaked exception from the application. | ||
logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}"); | ||
|
||
// Send a message to the user | ||
await turnContext.SendActivityAsync("The bot encountered an error or bug."); | ||
await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code."); | ||
|
||
// Send a trace activity, which will be displayed in the Bot Framework Emulator | ||
await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError"); | ||
}; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
samples/csharp_dotnetcore/86.bot-authentication-fic/Bots/EchoBot.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,31 @@ | ||
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.22.0 | ||
|
||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Schema; | ||
|
||
namespace Microsoft.BotBuilderSamples.Bots | ||
{ | ||
public class EchoBot : ActivityHandler | ||
{ | ||
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
var replyText = $"Echo: {turnContext.Activity.Text}"; | ||
await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText), cancellationToken); | ||
} | ||
|
||
protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
var welcomeText = "Hello and welcome to Echo Bot Using Federated Identity Credentials !!"; | ||
foreach (var member in membersAdded) | ||
{ | ||
if (member.Id != turnContext.Activity.Recipient.Id) | ||
{ | ||
await turnContext.SendActivityAsync(MessageFactory.Text(welcomeText, welcomeText), cancellationToken); | ||
} | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
samples/csharp_dotnetcore/86.bot-authentication-fic/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 @@ | ||
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.22.0 | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.Integration.AspNet.Core; | ||
|
||
namespace bot_authentication_fic.Controllers | ||
{ | ||
// 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] | ||
[HttpGet] | ||
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: 33 additions & 0 deletions
33
...oymentTemplates/DeployUseExistResourceGroup/parameters-for-template-AzureBot-with-rg.json
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,33 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"azureBotId": { | ||
"value": "" | ||
}, | ||
"azureBotSku": { | ||
"value": "S1" | ||
}, | ||
"azureBotRegion": { | ||
"value": "global" | ||
}, | ||
"botEndpoint": { | ||
"value": "" | ||
}, | ||
"appType": { | ||
"value": "MultiTenant" | ||
}, | ||
"appId": { | ||
"value": "" | ||
}, | ||
"UMSIName": { | ||
"value": "" | ||
}, | ||
"UMSIResourceGroupName": { | ||
"value": "" | ||
}, | ||
"tenantId": { | ||
"value": "" | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ploymentTemplates/DeployUseExistResourceGroup/parameters-for-template-BotApp-with-rg.json
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,48 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"appServiceName": { | ||
"value": "" | ||
}, | ||
"existingAppServicePlanName": { | ||
"value": "" | ||
}, | ||
"existingAppServicePlanLocation": { | ||
"value": "" | ||
}, | ||
"newAppServicePlanName": { | ||
"value": "" | ||
}, | ||
"newAppServicePlanLocation": { | ||
"value": "" | ||
}, | ||
"newAppServicePlanSku": { | ||
"value": { | ||
"name": "S1", | ||
"tier": "Standard", | ||
"size": "S1", | ||
"family": "S", | ||
"capacity": 1 | ||
} | ||
}, | ||
"appType": { | ||
"value": "MultiTenant" | ||
}, | ||
"appId": { | ||
"value": "" | ||
}, | ||
"appSecret": { | ||
"value": "" | ||
}, | ||
"UMSIName": { | ||
"value": "" | ||
}, | ||
"UMSIResourceGroupName": { | ||
"value": "" | ||
}, | ||
"tenantId": { | ||
"value": "" | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ot-authentication-fic/DeploymentTemplates/DeployUseExistResourceGroup/readme.md
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,48 @@ | ||
# Usage | ||
The BotApp must be deployed prior to AzureBot. | ||
|
||
Command line: | ||
- az login | ||
- az deployment group create --resource-group <group-name> --template-file <template-file> --parameters @<parameters-file> | ||
|
||
# parameters-for-template-BotApp-with-rg: | ||
|
||
- **appServiceName**:(required) The Name of the Bot App Service. | ||
|
||
- (choose an existingAppServicePlan or create a new AppServicePlan) | ||
- **existingAppServicePlanName**: The name of the App Service Plan. | ||
- **existingAppServicePlanLocation**: The location of the App Service Plan. | ||
- **newAppServicePlanName**: The name of the App Service Plan. | ||
- **newAppServicePlanLocation**: The location of the App Service Plan. | ||
- **newAppServicePlanSku**: The SKU of the App Service Plan. Defaults to Standard values. | ||
|
||
- **appType**: Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. **Allowed values are: MultiTenant(default), SingleTenant, UserAssignedMSI.** | ||
|
||
- **appId**:(required) Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings. | ||
|
||
- **appSecret**:(required for MultiTenant and SingleTenant) Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings. | ||
|
||
- **UMSIName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource used for the Bot's Authentication. | ||
|
||
- **UMSIResourceGroupName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource Group used for the Bot's Authentication. | ||
|
||
- **tenantId**: The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to <Subscription Tenant ID>. | ||
|
||
MoreInfo: https://docs.microsoft.com/en-us/azure/bot-service/tutorial-provision-a-bot?view=azure-bot-service-4.0&tabs=userassigned%2Cnewgroup#create-an-identity-resource | ||
|
||
|
||
|
||
# parameters-for-template-AzureBot-with-rg: | ||
|
||
- **azureBotId**:(required) The globally unique and immutable bot ID. | ||
- **azureBotSku**: The pricing tier of the Bot Service Registration. **Allowed values are: F0, S1(default)**. | ||
- **azureBotRegion**: Specifies the location of the new AzureBot. **Allowed values are: global(default), westeurope**. | ||
- **botEndpoint**: Use to handle client messages, Such as https://<botappServiceName>.azurewebsites.net/api/messages. | ||
|
||
- **appType**: Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. **Allowed values are: MultiTenant(default), SingleTenant, UserAssignedMSI.** | ||
- **appId**:(required) Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings. | ||
- **UMSIName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource used for the Bot's Authentication. | ||
- **UMSIResourceGroupName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource Group used for the Bot's Authentication. | ||
- **tenantId**: The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to <Subscription Tenant ID>. | ||
|
||
MoreInfo: https://docs.microsoft.com/en-us/azure/bot-service/tutorial-provision-a-bot?view=azure-bot-service-4.0&tabs=userassigned%2Cnewgroup#create-an-identity-resource |
119 changes: 119 additions & 0 deletions
119
...cation-fic/DeploymentTemplates/DeployUseExistResourceGroup/template-AzureBot-with-rg.json
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,119 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"azureBotId": { | ||
"type": "string", | ||
"metadata": { | ||
"description": "The globally unique and immutable bot ID." | ||
} | ||
}, | ||
"azureBotSku": { | ||
"defaultValue": "S1", | ||
"type": "string", | ||
"metadata": { | ||
"description": "The pricing tier of the Bot Service Registration. Allowed values are: F0, S1(default)." | ||
} | ||
}, | ||
"azureBotRegion": { | ||
"type": "string", | ||
"defaultValue": "global", | ||
"metadata": { | ||
"description": "Specifies the location of the new AzureBot. Allowed values are: global(default), westeurope." | ||
} | ||
}, | ||
"botEndpoint": { | ||
"type": "string", | ||
"metadata": { | ||
"description": "Use to handle client messages, Such as https://<botappServiceName>.azurewebsites.net/api/messages." | ||
} | ||
}, | ||
"appType": { | ||
"type": "string", | ||
"defaultValue": "MultiTenant", | ||
"allowedValues": [ | ||
"MultiTenant", | ||
"SingleTenant", | ||
"UserAssignedMSI" | ||
], | ||
"metadata": { | ||
"description": "Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. Allowed values are: MultiTenant, SingleTenant, UserAssignedMSI. Defaults to \"MultiTenant\"." | ||
} | ||
}, | ||
"appId": { | ||
"type": "string", | ||
"metadata": { | ||
"description": "Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings." | ||
} | ||
}, | ||
"UMSIName": { | ||
"type": "string", | ||
"defaultValue": "", | ||
"metadata": { | ||
"description": "The User-Assigned Managed Identity Resource used for the Bot's Authentication." | ||
} | ||
}, | ||
"UMSIResourceGroupName": { | ||
"type": "string", | ||
"defaultValue": "", | ||
"metadata": { | ||
"description": "The User-Assigned Managed Identity Resource Group used for the Bot's Authentication." | ||
} | ||
}, | ||
"tenantId": { | ||
"type": "string", | ||
"defaultValue": "[subscription().tenantId]", | ||
"metadata": { | ||
"description": "The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to \"Subscription Tenant ID\"." | ||
} | ||
} | ||
}, | ||
"variables": { | ||
"tenantId": "[if(empty(parameters('tenantId')), subscription().tenantId, parameters('tenantId'))]", | ||
"msiResourceId": "[concat(subscription().id, '/resourceGroups/', parameters('UMSIResourceGroupName'), '/providers/', 'Microsoft.ManagedIdentity/userAssignedIdentities/', parameters('UMSIName'))]", | ||
"appTypeDef": { | ||
"MultiTenant": { | ||
"tenantId": "", | ||
"msiResourceId": "" | ||
}, | ||
"SingleTenant": { | ||
"tenantId": "[variables('tenantId')]", | ||
"msiResourceId": "" | ||
}, | ||
"UserAssignedMSI": { | ||
"tenantId": "[variables('tenantId')]", | ||
"msiResourceId": "[variables('msiResourceId')]" | ||
} | ||
}, | ||
"appType": { | ||
"tenantId": "[variables('appTypeDef')[parameters('appType')].tenantId]", | ||
"msiResourceId": "[variables('appTypeDef')[parameters('appType')].msiResourceId]" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"apiVersion": "2021-05-01-preview", | ||
"type": "Microsoft.BotService/botServices", | ||
"name": "[parameters('azureBotId')]", | ||
"location": "[parameters('azureBotRegion')]", | ||
"kind": "azurebot", | ||
"sku": { | ||
"name": "[parameters('azureBotSku')]" | ||
}, | ||
"properties": { | ||
"displayName": "[parameters('azureBotId')]", | ||
"iconUrl": "https://docs.botframework.com/static/devportal/client/images/bot-framework-default.png", | ||
"endpoint": "[parameters('botEndpoint')]", | ||
"msaAppId": "[parameters('appId')]", | ||
"msaAppTenantId": "[variables('appType').tenantId]", | ||
"msaAppMSIResourceId": "[variables('appType').msiResourceId]", | ||
"msaAppType": "[parameters('appType')]", | ||
"luisAppIds": [], | ||
"schemaTransformationVersion": "1.3", | ||
"isCmekEnabled": false, | ||
"isIsolated": false | ||
}, | ||
"dependsOn": [] | ||
} | ||
] | ||
} |
Oops, something went wrong.