Error on returning message from bot (Forbidden) - botframework

I am creating a bot on facebook and as per the logs I am having , The message is reaching the bot but when the bot is responding I am getting the below error
"System.UnauthorizedAccessException: Authorization for Microsoft App ID failed with status code Forbidden at Microsoft.Bot.Connector.JwtTokenRefresher.d__2.MoveNext()"
I tried on facebook/skype and it's the same error. I added message.From but still facing some issue.
Here is my message returning code.
Activity replyMessage = message.CreateReply();
replyMessage.Text = "Text";
replyMessage.TextFormat = "plain";
await connector.Conversations.ReplyToActivityAsync(replyMessage);
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;

Have you registered the bot on the Bot Framework portal? If so, make sure that you are using the correct MicrosoftAppId and MicrosoftAppPassword in your project's web.config. The error you are having it seems an authentication issue, which basically means that your settings in the web.config are not the expected ones

Related

Bot Channels Registration - There was an error sending this message to your bot: HTTP status code Unauthorized

I am in the process of building a chat bot that will integrate with Teams or Slack. To get started I am using the echo bot template, but I am adding it to an exiting API that I have in my Service Fabric Cluster.
When running the application locally, I can connect to it fine from the Bot Emulator, but when I deploy it to my Azure channel registration, and test it in the web chat I get:
There was an error sending this message to your bot: HTTP status code Unauthorized.
I am setting the AppID and Password and they are saved and being retrieved from KeyVault, and I throw an exception at startup if either of the values are blank (which is not the case).
I set it as follow:
services.AddBot<EchoBot>(options =>
{
options.CredentialProvider = new SimpleCredentialProvider(Configuration["MicrosoftAppId"], Configuration["MicrosoftAppPassword"]);
options.OnTurnError = async (context, exception) =>
{
ServiceEventSource.Current.Message(exception.Message);
await context.SendActivityAsync("Sorry, it looks like something went wrong.");
};
});
I have added a teams channel, where the error does not occur, but the message never reaches the server.
The service is reachable and the controller allows unauthorized credentials while this is in testing.
Solved my own issue.
It turns out that if you are using a self signed certificate, then this could occur, as per Microsofts documents found here -
If one or more error(s) are indicated in the chat window, click the error(s) for details. Common issues include:
The emulator settings specify an incorrect endpoint for the bot. Make sure you have included the proper port number in the URL and the proper path at the end of the URL (e.g., /api/messages).
The emulator settings specify a bot endpoint that begins with https. On localhost, the endpoint should begin with http.
In the emulator settings, the Microsoft App ID field and/or the Microsoft App Password do not contain valid values. Both fields should be populated and each field should contain the corresponding value that you verified in Step 2.
Security has not been enabled for the bot. Verify that the bot configuration settings specify values for both app ID and password.
Lessons Learnt
Read the doc's
When you get frustrated, calm down and read the doc's

Chatbot is not working once created the Web App bot in Azure bot service

I created a Web app bot in Azure portal. LUIS, App service, Insights got created automatically. This is a Basic bot using SDK-V4. It got created successfully. But after it when i tried to test the bot using "Test in Web Chat" it gave the "Failed to send activity: bot returned an error". I didn't even deployed any code for the bot.
PFB the screenshot of the issue below.
I just downloaded the bot source code and did some changes. It is working fine in Emulator by getting connected to LUIS. But in "Test using web chat" it is not working even with or without deployment of code.
I checked the following already:
Message Endpoints.
MS App ID and MS App Password in App service.
Actual getting results:
In App Insights:
Message : POST to SAP_Bot-DEV failed: POST to the bot's endpoint failed with
HTTP status 500 POST to the bot's endpoint failed with HTTP status
500.
Failed Message: Microsoft.Bot.ChannelConnector.BotAPI.ThrowOnFailedStatusCode
Call Stack:
Microsoft.Bot.Schema.BotException:
at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__31.MoveNext (Microsoft.Bot.Base.ChannelConnector, Version=3.2.3.0, Culture=neutral, PublicKeyToken=null)
Inner exception System.Exception handled at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__31.MoveNext:
at Microsoft.Bot.ChannelConnector.BotAPI.ThrowOnFailedStatusCode (Microsoft.Bot.Base.ChannelConnector, Version=3.2.3.0, Culture=neutral, PublicKeyToken=null)
at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__31.MoveNext (Microsoft.Bot.Base.ChannelConnector, Version=3.2.3.0, Culture=neutral, PublicKeyToken=null)
In Browser:
{error: {code: "BotError", message: "Failed to send activity: bot returned an error"},…}
error: {code: "BotError", message: "Failed to send activity: bot returned an error"}
httpStatusCode: 500[In Browser][1]
[App Insights Screenshot][2]
Try publishing your bot and check if the messaging endpoint url is not set to localhost but to your published url in azure and in registration portalset your messaging endpoint as the redirect url
The issue got resolved. Initially we created the MS application ID and password manually by creating an application in azure portal. There was some issue with the manually created ID, then we tried with automatic app ID creation (after getting required authorization in azure portal) and it works. Thank you all for your support.

Using EWS API send email method get 401 unauthorized

I'm very new to EWS API. Now I've a problem when I Send Email using EWS sample. Still getting the error:
401 unauthorized.
Here is my sample code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("user1#contoso.com", "password");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("user1#contoso.com", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("user1#contoso.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API");
email.Send();
The error in the email.Send() function. Any help for this?
Related link:https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/get-started-with-ews-managed-api-client-applications
I searched all links but no correct answer.
I've checked your provide link and not found any problem. In general, There is no problem in writing this way. The problem should be related to your server environment or account as wannadream mentioned.
You can refer to the following links:
"(401) Unauthorized" error when you use an EWS application to impersonate a user in Office365 Dedicated/ITAR
Exchange Web Service API and 401 unauthorized exception
Also, could you please change your account to test it?
Shot in the dark, but easy to try: several years ago I was getting unexplained 401s, and found some web post that mentioned adding an empty cookie container to the service object, i.e.:
service.CookieContainer = new CookieContainer();
It seemed to do the trick at the time, but not sure if it's still a thing.

Windows Store App Push Notifications via Azure Service Bus

I'm trying to send a push notification to my Windows Store App developed in my laptop using VS 2013 Express. It's been few days now but I cannot figure out why I get "The Token obtained from the Token Provider is wrong" error. I use Windows Azure Notification Bus for this purpose. I use VS Server Explorer to send test notifications. I can see my laptop is being registered as a device in the Device Registration tab too. I tried the Azure portal as well, but the same error. However, when I try to connect to Service Bus Explorer 2.4.3.0 providing the connection string it throws below error.
<21:47:14> Exception: The remote server returned an error: (401) Unauthorized. Manage claim is required for this operation..TrackingId:c0c4fea2-08bc-4def-964c-ec6e690b7551_G45,TimeStamp:10/12/2014 4:17:11 PM. Method b__7e: retry 2 of 10.
FYI: I'm following below article step by step.
http://azure.microsoft.com/en-us/documentation/articles/notification-hubs-windows-store-dotnet-get-started/
Please help me. Thank you.
Mahesh
Looks like token is just expired. Make sure you obtain token each time application starts. In terms of the article you refer it means you should call method InitNotificationsAsync() to do it. Here is that method:
private async void InitNotificationsAsync()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var hub = new NotificationHub("<hub name>", "<connection string with listen access>");
var result = await hub.RegisterNativeAsync(channel.Uri);
// Displays the registration ID so you know it was successful
if (result.RegistrationId != null)
{
var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}

gdata SetAuthenticationToken() - 403 forbidden

I am just trying to get list of Albums in a web app using following c# code.
For AccessToken, I wen to OAuthPlaygound and generated an accessToken
with Picasa in scope using valid consumer key and password which relevant to my web application.
Issue :When I execute following code, I get 403 forbidden error along with message as "Invalid Token" error on last line if I use SetAuthenticationToken() option.
However, if I use setUserCredentialss(), it works. Could anyone please
help me in this? Is it that token generated using OAuth Playground
doesn't work here? Or to use client library token should also be geenrated using it? Is there any workaround?
PicasaService service = new PicasaService("codesamples.google.com");
service.SetAuthenticationToken(accessToken); //Doesn't works
//service.setUserCredentials("myUsername", "myPassword"); //Works
AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(username));
PicasaFeed feed = service.Query(query);

Resources