I am currently following Teams Conversation Bot sample. I have followed it to the letter as far as i can see.
What works.
When i talk to the bot though the web view
I can see it hitting the code on my localhost.
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
turnContext.Activity.RemoveRecipientMention();
switch (turnContext.Activity.Text.Trim())
{
case "MentionMe":
await MentionActivityAsync(turnContext, cancellationToken);
break;
case "UpdateCardAction":
await UpdateCardActivityAsync(turnContext, cancellationToken);
break;
case "Delete":
await DeleteCardActivityAsync(turnContext, cancellationToken);
break;
case "MessageAllMembers":
await MessageAllMembersAsync(turnContext, cancellationToken);
break;
default:
var value = new JObject { { "count", 0 } };
var card = new HeroCard
{
Title = "Welcome Card",
Text = "Click the buttons below to update this card",
Buttons = new List<CardAction>
{
new CardAction
{
Type= ActionTypes.MessageBack,
Title = "Update Card",
Text = "UpdateCardAction",
Value = value
},
new CardAction
{
Type = ActionTypes.MessageBack,
Title = "Message all members",
Text = "MessageAllMembers"
}
}
};
await turnContext.SendActivityAsync(MessageFactory.Attachment(card.ToAttachment()));
break;
}
}
what doesn't work
It appears to send the response back but nothing appears in the response window. How do i test this if it doesn't show the response?
Ngrok error
After a bit more digging I can see that ngrok is getting an error back of sorts its a web page I managed to pick the following error out of it.
AggregateException: Failed to acquire token for client credentials. (AADSTS700016: Application with identifier '9e0d71-7665-4f24-8898-f82f9bebba56' was not found in the directory 'botframework.com'. 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.
Trace ID: 4bf53bae-84dc-4b16-98e8-e99b322dc200
Correlation ID: 3c249469-d177-49dd-989f-80044a3b9faa
Timestamp: 2019-11-12 08:41:56Z) (AADSTS700016: Application with identifier 'e0d71-7665-4f24-8898-f82f9bebba56' was not found in the directory 'botframework.com'. 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.
I have checked the settings on the bot and the application itself. They have the same secret and application client id.
botframework.com appears to contain a list of bots that were created on azure.
What i have tried.
Visual studio is running as administrator.
Chckedbotframework.com my bot is listed.
Users have the write to create apps in AD, I am currently the only user anyway.
dev tools logs shows its authenticating.
Edge and chrome
web chat errors
I can see in the bot that its logging errors with the web chat
The thing is the bot is responding.
Emulator
Running the emulator does work. The issue is when hosted.
cross posted
Issue #1974
I realize this is an old thread but I just got hit by this today. After much pain, the fix in our situation was this:
Go to Azure Portal > Azure Active Directory
Click "App registrations"
Find the registration for the bot app in question and click on it.
Under Manage, choose Authentication.
Change "Supported account types" to "Accounts in any organizational directory."
In retrospect: the AADSTS700016 error was thrown when trying to get the detailed info of the person the bot is chatting with via Microsoft.Bot.Builder.Teams.TeamsInfo.GetMemberAsync(). Since our "Supported account types" in the app registration was restricted, when the bot was running in a Teams Office365 Tenant that was different than our Azure AD Tenant, Azure AD was saying, "Nope." After flipping this, then GetMemberAsync() was able to authenticate aginst the Teams Office365 Tenant to obtain the requested user information. Yay!
Related
I'm trying to get my user to authenticate with Microsoft Graph. I've been trying to use one of the Microsoft examples:
https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/24.bot-authentication-msgraph
It asks for a string 'ConnectionSettingName' which it then uses in the OAuthHelpers.cs class for the OAuthPrompt Prompt, however the prompt accepts (and does not error) the string regardless of what is inputted as the ConnectionSettingName and does not prompt the user within the emulator. When debugging I see that this OAuthPrompt Prompt below attempts to run, but nothing gets returned.
public static OAuthPrompt Prompt(string connectionName)
{
return new OAuthPrompt(
"loginPrompt",
new OAuthPromptSettings
{
ConnectionName = connectionName,
Text = "Please login",
Title = "Login",
Timeout = 300000, // User has 5 minutes to login
});
}
It then bypasses this and goes on to show the welcome card in the emulator. If I click on any of the options to query the Graph (Me, Logout, Help, etc...) the emulator freezes as I have not been able to authenticate yet. Could anyone give some insights on why my OAuthPrompt is not displaying?
As a note, within the bot framework emulator under App settings I've checked the boxes 'Use a sign-in verification code for OAuthCards'. I've tried this with it both on and off with no results.
Thank you for reading.
I start investigating BotFramework and encountered one annoying issue.
Created "Hello world" bot.
Here if the code
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
// return our reply to the user
Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
await connector.Conversations.ReplyToActivityAsync(reply);
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
It works fine locally
Deployed it on Azure.
Set correct BotId, MicrosoftAppId and MicrosoftAppPassword parameters in web.config.
URL with my bot is http://funnyskypebot20171026010946.azurewebsites.net and it looks it works
But when i try to "communicate" with bit via Bot Framework Channel Emulator i do not receive any messages back ...
What could be wrong ? Please advise.
I assume you already followed the steps in https://learn.microsoft.com/en-us/bot-framework/deploy-dotnet-bot-visual-studio for deployment to Azure.
Have you seen this https://learn.microsoft.com/en-us/bot-framework/debug-bots-emulator with regards to debugging remotely using ngrok?
If you are using Visual Studio, on the toolbar, you can click on 'View -> Server Explorer'. Under 'Azure -> App Service', you should see your resource group there. Under your resource group, you should see your app service. Right-click and select 'Attach Debugger' so that you can view the output ('View -> Output') and debug your deployed app service.
Internal server error generally means there is some sort of issue with your code. Try debugging locally using ngrok. You can change your endpoint in the dev portal to the one that ngrok generates when you use this command ngrok http 3979 -host-header="localhost:3979" change to the port your bot runs on.
More info:
Blog Post
Blog Post
I'm trying to build a separate app - basically a daemon running on my intranet - that can connect to a Bot Connector app and access an existing conversation between a user and the bot.
To start at this, I'm using the DirectLine NuGet package, and then searching for existing messages with the conversationId found in a conversation I've started with the bot via the emulator.
For example, I fired up the emulator, and got the conversationId "8a684db8". Over in my console app, I've got the following relevant code:
var uri = new Uri("https://directline.botframework.com");
DirectLineClientCredentials creds = new DirectLineClientCredentials(secret); //lot into the bot framework
DirectLineClient client = new DirectLineClient(uri, creds); //connect the client
Conversations convs = new Conversations(client); //get the list of conversations belonging to the bot? Or does this start a new collection of conversations?
var existing_conv_messages = convs.GetMessages(convo_id);
Now, when I try to run it, I'm getting a "Not Found" error on the last line where I tried to find existing messages.
Anyone have a solution here?
Conversations sent to the emulator don't get sent to the Direct Line API. For messages to be viewable in Direct Line, they need to be sent through the online, running Connector and Direct Line services.
I am creating a Windows 8.1 application, and I want to use it with multiple accounts. When I first started the application, I used the wl.signin scope to test the app faster, but I want to test now with other account(s). So I deleted this scope, I uninstalled the app from my computer, and from my Live Account I removed the apps permissions.
Still, if I want to log in for the first time, the app wants permission for automatic login(== wl.signin, which I deleted from my scopes already as I mentioned before).
Basically, I want to achieve to write my user credentials every time I want to use the app so I could login with other accounts.
Here is the code for login:
LiveLoginResult result = await App.Auth.InitializeAsync(new string[] { "wl.basic" });
if (result.Status != LiveConnectSessionStatus.Connected)
result = await App.Auth.LoginAsync(new string[] { "wl.basic" });
if (result.Status == LiveConnectSessionStatus.Connected)
{
await App.MobileService.LoginWithMicrosoftAccountAsync(
result.Session.AuthenticationToken);
App.Lcs = result.Session;
}
else
{
await dialogService.ShowMessage("Not logged in.", "Error!");
}
And if I try to log out, the CanLogout always returns with false value.
if (App.Auth.CanLogout)
{
App.Auth.Logout();
navigationService.NavigateTo("MainPage");
}
What am I missing here? Maybe the scopes cached somewhere else? Could that be a problem if I use the operating system with Microsoft Account? Or if I associated the app with a Store app with Visual Studio?
It's not possible with LiveSdk. Because LiveSdk uses account info from the system. The only way to use few accounts at once, is to develop an own SDK via LIVE REST API (as in the LiveSDK internally).
I'm using the v5.3 Live SDK for a Windows 8 Store App (XAML/C#) and I have a question.
In my app, if the user is logged into Windows using a Microsoft
Account, then I want to grab the firstname/lastname/Microsoft ID.
If they are logged in to Windows using a local account and haven't
logged in to my app, then I want to show a 'Login' button, so they
can enter their Microsoft account email/password.
I know how to do all that using the Live SDK, but my question is - how can I tell if the user is logged into Windows with a Microsoft account versus a Local Account that hasn't been logged in to the MS account?
I can use the following:
var idAuth = new OnlineIdAuthenticator();
return idAuth.CanSignOut;
but this will return false if either the 2 criteria above is true (and return true if the user is using a local account, but has logged in to my app using Microsoft account details).
In theory, if the above returns false, I can do the following:
LiveAuthClient authClient = new LiveAuthClient();
LiveLoginResult authResult = await authClient.LoginAsync(new List<string>() { "wl.signin" });
if (authResult.Status == LiveConnectSessionStatus.Connected)
{ //Get user info here }
The problem is that this works fine for a user logged into windows using a Microsoft Account - their info is picked up fine, but if it is a user logged into Windows with a local account, then it is going to show the Live Login screen in my app - at that point I don't want to do that, rather just show a logon button in my UI.
Anyone any ideas on how to tell the difference between the 2 criteria above?
Thanks in anticipation,
Richard.
I ended up asking the same question on the MSDN forums and got an answer there, so I am posting it here just in case it helps anyone else.
http://social.msdn.microsoft.com/Forums/en-US/messengerconnect/thread/f6946851-b495-45f6-95a4-eb3c2a004c0e