Im currently trying to send a message from the Bot Framework Emulator to the Test Web Chat in Azure. My Problem is when trying this:
var my2Response = await myClient.SendAsync(request).ConfigureAwait(false);
I get StatusCode: 403, ReasonPhrase: 'Forbidden',
and I don't know what I should do here. I noticed that request.Content
also has Headers and tried this crazy thing: request.Content.Headers.Add("Authorization", "Bearer " + myToken);
but as you might guessed it, this is not the solution. How can I send a post to my Azure Test Webchat via Botframework? (if that works I want to try to send a message to the Test Webchat via MS Teams)
Here is the related code:
HttpClient myClient = new HttpClient();
myClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var myToken = token;
myClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", myToken);
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new System.Uri("https://webchat.botframework.com/v3/conversations/conversationID/activities"),
Content = new StringContent("{\"type\": \"message\", \"text\": \"I come from teams\", \"from\": {\"id\": \"bot@somthing\", \"name\": \"teams\"}}", System.Text.Encoding.UTF8),
};
request.Content.Headers.ContentType.MediaType = "application/json";
request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
request.Headers.Add("Authorization", "Bearer " + myToken);
var my2Response = await myClient.SendAsync(request).ConfigureAwait(false);
my2Response.EnsureSuccessStatusCode();
var myResponseBody = await my2Response.Content.ReadAsStringAsync().ConfigureAwait(false);
edit
The token I'm using is generated from here: https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token