The Bot Framework WebChat control isn't working with the Token protocol, as described in the Embed the Chat Control docs. Here's the code I'm having trouble with:
string webChatSecret = ConfigurationManager.AppSettings["WebChatSecret"];
var request = new HttpRequestMessage(HttpMethod.Post, "https://webchat.botframework.com/api/conversations");
request.Headers.Add("Authorization", "BOTCONNECTOR " + webChatSecret);
HttpResponseMessage response = await new HttpClient().SendAsync(request);
string responseJson = await response.Content.ReadAsStringAsync();
WebChatTokenResponse webChatResponse = JsonConvert.DeserializeObject<WebChatTokenResponse>(responseJson);
return $"<iframe width='400px' height='400px' src='https://webchat.botframework.com/embed/PigLatinBotJoeMayo?t={webChatResponse.Token}'></iframe>";
the WebChatTokenResponse is
public class WebChatTokenResponse
{
public string ConversationID { get; set; }
public string Token { get; set; }
}
When I debug and hit a breakpoint, I do have a ConversationID and a Token. No exceptions are being thrown.
If I just use the secret, like this (instead of the code above, everything works:
string webChatSecret = ConfigurationManager.AppSettings["WebChatSecret"];
return $"<iframe width='400px' height='400px' src='https://webchat.botframework.com/embed/PigLatinBotJoeMayo?s={webChatSecret}'></iframe>";
Here are the error messages I'm seeing with F12 tools:
I'm seeing a 500 Internal Server Error on
Request URL: https://webchat.botframework.com/api/conversations
with the error message:
{ "message": "An error has occurred." }
If I enter a 'hi' message to:
Request URL: https://webchat.botframework.com/api/conversations/null/messages
I receive a 403 Forbidden message with the response:
{ "message": "Invalid token or secret" }
Update
I blogged about how I got this working at Using the Bot Framework Chat Control.