Teams Bot - get credentials from Key Vault - botframework

I have searched a bit but didn't found something which is helping me. I created a bot for teams and like described in all examples I am using the appsettings.json to store the ID and the password for the bot (MicrosoftAppId and MicrosoftAppPassword). These are both handled by the framework somehow. But now I want to use an Azure Key Vault to store the secret instead of having the appsettings file.
So I found some examples explaining how to do this in BotFramework V3 with BotAuthentication Attribute and even something for BotFramework V4 here (working link for the linked example here). But even that example is old and does not exist anymore like that.
How am I supposed to do this for a teams bot and c# dotnet 3.1?

You can use the following method to store the secret value
var storageSecretValue = keyVaultClient.GetSecretAsync($"{this.configuration.GetSection("KeyVault")["BaseURL"]}{this.configuration["KeyVaultStrings:StorageConnection"]}");
please refer the following sample document to more clarification:-
https://github.com/OfficeDev/microsoft-teams-apps-newemployeeonboarding/blob/main/Source/Microsoft.Teams.Apps.NewHireOnboarding/Startup.cs
https://learn.microsoft.com/en-us/samples/azure-samples/key-vault-dotnet-core-quickstart/get-started-keyvault-net/

Related

How to create a token generation API in the Bot Composer C# solution?

I'm new to C# development and know we should be able to host the token generation C# api within the Bot Composer C# solution to safely use the DirectLine Secret to get a token.
Can anyone provide steps and/or sample code?

Microsoft Bot Framework - bot missing from "Bot Framework" tenant. How to add?

Half a year ago we created a bot using the App Studio app from Teams. This worked well and the bot is running happily. Apparently starting 2022 App Studio "evolved":
So, this time using the new "evolved" Developer Portal, we registered a similar bot in another environment.
Just to end up with a bot that somehow is not registered in the Microsoft-internal bot framework tenant. I cannot say how we ended up in this state but there is a troubleshooting site that we can use to verify our failed state. The result of this simple call looks like this:
For googleability:
AADSTS700016: Application with identifier
'68dafaa0-5755-4433-8f47-3e174c5ed131' was not found in the directory
'Bot Framework'. This can happen if the application has not been
installed by the administrator of the tenant or consented to by any
user in the tenant. You may have sent your authentication request to
the wrong tenant.
Now the question: how can we add our bot to this "Bot Framework" tenant? And: which of the button clicks in the Dev Center and/or Bot Framework portal do the magic of adding the bot? The troubleshooting article unfortunately gives no advice on how to fix this situation.
We also tried removing the bot via the Bot Framework portal and re-created it with the same IDs and had the hope this fixes the situation. Unfortunately not.
Note: everything else is in place and looks like our other functioning bot. A teams app containing the bot, the Azure AD app registration with the bot ID, the bot in the bot portal, correct client secret. Everything seems correct except that the bot ID is missing from the Bot Framework tenant.
Just ran into the same issue. It looks like you have your bot registered into your tenant (and not the global bot framework). So you can get the access token by changing the URL to the following (replacing with your tenant id):
https://login.microsoftonline.com/YOUR-TENANT-ID/oauth2/v2.0/token
Just tested this and was able to get an access token. Now will that token actually work the same way using the scope is another matter. You may need to change the scope to:
https://graph.microsoft.com/.default
As of now I am getting a token either way
To generate a bot directly into the global tenant you can go to the following URL and click on "My Bots" and then "Create". Any existing bots you have should also appear here:
https://dev.botframework.com/

How to deploy botbuilder sample as Azure Function

I'd like to deploy one of the dotnetcore botbuilder samples as an Azure function and point the bot service registration at the Azure function.
I've found a few posts that describe this sort of thing but they seem to refer to v3 of the SDK.
Is this possible with the v4 SDK? If so, is there a sample that demonstrates this or can you provide guidance on what changes are required to the project/code to achieve this?

News sample skill returns unauthorized error

I am trying to use the experimental skills provided by the bot framework. I downloaded the code for the news skill and created all azure resources. I got the bing key from here and placed it in my appsettings.json I also updated all my config values to my Luis app.
I am testing through emulator. When I run the code I go through the dialog successfully, it asks me for the topic I want to get news about and my country and then at the point where it has to get the news articles I get the following error.
Does anyone have any idea what am I missing? I tried the bing API through postman using the same key I have in my appsettings and it is working fine.
Should I do an additional step other than just download the code and update all the config values?
I don't know what is causing this error.
If you have created bing using new marketing portal.
Here are endpoints for Bing news using REST API.
Doc Location: https://learn.microsoft.com/en-us/bing/search-apis/

Can't change language in botframework

I created a bot in botframework (microsoft Azure) connect to a LUIS App. It worked all very well. But in english. The connection between the Bot and LUIS App has been done automatically.
Now I want it to work in German. So I created a new App in luis with de-de culture. Created my german intents. Published it.
I followed the instructions from LUISChatBot. I could retrieve LUIS AppID and Authorizing Key as well as the endpoint of the German LUIS App to add it to my Azure chat bot. And the bot continues to understand only the intents in english!
So I guess the connection doesn't work how it is explained in the instructions above. Even worse : even if I put nothing ( = I remove the ID and Key and let it empty) in LuisAPIkey or LuisAPIId represented in the image of the Azure Chatbot settings, the bot continues to understand the english intents !?!
How can I make it work? I looked in the code of the bot, but I don't find the key appearing there (which makes sense). The only think I found, was in BasicLuisDialog.cs :
public BasicLuisDialog() : base(new LuisService(new LuisModelAttribute(
ConfigurationManager.AppSettings["LuisAppId"],
ConfigurationManager.AppSettings["LuisAPIKey"],
domain: ConfigurationManager.AppSettings["LuisAPIHostName"])))
{
}
Thank you for your time
Half-Answer : I could change the language by changing the region in Azure (west EU) and then also use eu.luis.ai.
But I still don't know why the chatbot continued working when I removed the key and endpoint of LUIS in Azure.
you can use
var english = new Option();
english.Locale = "en-US";
Reference: GitHub
or
In BotSDK v4.0, you can use System.Globalization.CultureInfo("en-US"); to translate your existing language to the language you needed.

Resources