"Cannot post activity. Unauthorized" When testing from Bot Emulator - botframework

While testing the EchoBot template from Azure in Bot Emulator I keep getting "Cannot post activity. Unauthorized." How can I protect against this? I am new to .NET, so don't understand the how authentication is working here. I can see the configuration settings being loaded, but I don't see how they get supplied or applied in the default EchoBot template from Azure.
I have found I only get Unauthorized, if I have the "MicrosoftAppID" and "MicrosoftAppPassword" defined in the appsettings.json. If I comment these out it works fine.
[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);
}
So I would like to understand how to avoid having to comment these lines out when testing the code locally. PostAsync returns the 401.

Have you tried adding your Microsoft App ID and Microsoft App Password inside of the Emulator ?
It should work fine after you add those when you test the bot in the emulator, check picture below

Go to your appSettings.json file and check if you have provided Microsoft App ID and App Password. You will get it when you have registered your app on Azure. If you haven't register it on Azure, you won't get ID and password. In this case, you must left the Microsoft App Id and Password json string as blank. Something like this:
In the Bot Emulator, don't give any credentials. Just provide your app URL and click Connect.
By this way you can get rid of the error.
Hope this helps.

Related

In virtual assitent ,IBotFrameworkHttpAdapter.Adapter.Processasync menthod render the error :"Error invoking the skill id: error code 401."

We are trying to create virtual assistant bot microsoft teams. When we are trying to send request to skill bot from root bot using SkillClient.PostActivityAsync method, while debugging request hits botcontroller of skill bot. But it return 401 unauthorized error. If we try same in local using bot framework emulator (without using app id and password) it is working as expected. And how we can resolve this unauthorized error?
"When we use root bot with the different simple skill bot, it is working. but when we use app having client app (for tabs and Messaging extensions built using react) and additional authorization required for it. at that time it is throwing the above error"
Thanks!

MS Teams Messaging Extension submitTask failing with "v3 agent not found" error

I'm creating my first Microsoft Teams extension. For now I'm just trying to get the basic plumbing for a messaging extension working. I'm trying to build an extension which will allow a user to search for content in my service and then return a card into their compose window in personal and Teams chats.
I've tried to follow the basic guide ( https://learn.microsoft.com/en-us/microsoftteams/platform/messaging-extensions/how-to/create-messaging-extension ) for creating a messaging extension using App Studio. I've setup a bot as it describes, and I have built a dummy echobot endpoint for the bot (using Ruby). I am able to "chat" with my bot directly in the Teams client and it is able to respond.
My messaging extension defines an action based command with a taskInfo with a web view URL to render and a fetchTask set to false. I've written a basic static HTML page for this and included the teams-js library. The web view loads and the teams-js library initialization callback is called. I have a submit button which calls microsoftTeams.tasks.submitTask which as I understand it, should be calling my bot with a "composeExtension/submitAction" message to which I would respond with the card. (Based on https://learn.microsoft.com/en-us/microsoftteams/platform/messaging-extensions/how-to/action-commands/respond-to-task-module-submit?tabs=json )
I've tried installing my extension in Teams through the "Upload a custom app" option both as a "for me and my teams" and "for " but still have the following issues.
When I open my extension in the Teams client from the compose area and click this submit button in my iframe content, the submit I get a "Unable to reach app. Please try again" error displayed. In the dev console, I can see that the response to the "invoke" http post is {"errorCode":404,"message":"V3 agent not found."}
No traffic is actually sent to my bot during any of this process.
I saw this older post - Compose extension is throwing error : V3 agent not found . The https://dev.botframework.com/bots/ it refers to seems to be outdated, but in the Azure "Bot Channels Registration" console, I have gone to Channels and added "Microsoft Teams" (which I believe is the new equivalent).
Has anyone seen this happen and figured out what was going on? Much thanks!
Here is sample code for composeExtension/submitAction for Bot SDK V3. Make sure you pass the bot id and command text in taskInfo object.
case "composeExtension/submitAction":
string commandid = JsonConvert.DeserializeObject<Models.TaskModuleSubmitData<string>>(activityValue).commandId;
taskInfo = GetTaskInfo(commandid);
taskEnvelope = new Models.TaskEnvelope
{
Task = new Models.Task()
{
Type = Models.TaskType.Continue,
TaskInfo = taskInfo
}
};
return Request.CreateResponse(HttpStatusCode.OK, taskEnvelope);
Hilton had the right answer.
I had grabbed the Subscription ID from the Bot Channels Registration page instead of the App ID from the Azure Active Directory -> Apps Registration page and used that in the messaging extension manifest as the "botId" in the composeExtensions array. After fixing that I'm now getting messages submitted to my bot backend.

Tried code from Microsoft.Bot.Sample.AadV2Bot but even locally get AADSTS50011 (reply url doesn't match)

I've integrated the Code from Microsoft.Bot.Sample.AadV2Bot in my own bot but the GetTokenDialog call always results in error "AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application: 'MYBOTSAPPID'"
As far as I understood, I do not have to register my bot in Azure Portal under "Azure Active Directory" but setup the Reply URL in the application registration Portal (https://apps.dev.microsoft.com) - Correct?
But whatever values I enter here, it won't work, neither locally via Emulator nor via Web. Furthermore, in MS Teams the signin Dialog does not work at all.
I've already tried these reply URLs without success:
https://MYBOTSNAME.azurewebsites.net, http://localhost:3978 and https://localhost:44362
I also tried to extend these with /api/messages, /signin-oidc and several other combinations, all without success.
The mentioned sample solution also does not include more keys than ConnectionName, MicrosoftAppId and MicrosoftAppPassword in web.config, so I haven't got a clue which redirect URI is taken on runtime.
In Azure Portal I've created an Azure Active Directory V2 Connection on my bot and entered my bot's Microsoft App ID in the field "Client ID" and Microsoft App Password in the field "Client Secret" - is this correct?
Any hint what I might have done wrong is VERY welcome!!
I finally could solve the Reply URL mismatch problem myself. Had to enter this Reply URL on my app in the application Registration Portal to make it work locally, via Emulator:
https://token.botframework.com/.auth/web/redirect
Still, the authentification Dialog (GetTokenDialog class from Microsoft.Bot.Builder.Dialogs) doesn't popup when I use MS Teams as channel.
Does anyone have an idea what could help?

Azure Bot Service Error Message

I am having a problem trying to create a Microsoft App ID and password for my Bot. After creating a bot on Bot Service on the Azure portal I try to create a Microsoft App ID.
When I click the Create Microsoft App ID and password button as shown on the image above, it opens a new tab and I get this error message:
I'm also having problems with a previously created bot. When I go to All Resources on the Azure portal and click on that previously created bot I get the following error message:
Unable to find the specified id
I thank you in advance for your time and help :)
I definitely saw this happening on some MSA accounts, it's not a Bot Framework or Azure Bot Service issue. Two things you might try:
try creating MSA AppId and Password directly from https://apps.dev.microsoft.com/
If this doesn't work, do you have another MSA account you could try with?
Hope this helps
Andrea
I've seen this error before. Retrying fixed the issue for me (click Create Microsoft App ID and password button again). Please try again. You might need to sign out, clear your cookies, and sign back in.

How to check credentials against botframework api

I'd like to check that my bot credentials (appId + appSecret) are ok to connect to https://api.botframework.com/bot/v1.0/messages.
I can't send a real message because i have no conversation running so I tried to post the following json message :
{ "type": "Ping"} but the response i got was
{
"error": {
"message": "Expression evaluation failed. Object reference not set to an instance of an object.",
"code": "ServiceError"
}
}
Is there any way to check if my access to the api is ok?
If you've registered your bot, you can visit the Bot Framework page, click on the My Bots menu, and select your registered bot. On your bot page, scroll down to the bottom left and there's a test box.
Also, you can use the emulator. It has a place in the upper right corner to replace the default credentials with your bot credentials. Then change the URL to where you have your bot deployed. Tip: remember to append 'api/messages' to the URL.
Download the BotFrameworkEmulator to test connectivity to your bot. It works on windows and OSX if you have mono installed. You can change the default settings that the emulator uses by typing '/settings' after running it. You will be prompted to enter your appId, appSecret and url endpoint for sending and receiving messages to/from your bot.
You can also use the directline rest api to initiate conversations and send messages to your bot

Resources