BotFramework-WebChat icon indicating copy to clipboard operation
BotFramework-WebChat copied to clipboard

Disable Magic Code

Open fj4870 opened this issue 6 years ago • 1 comments

We have built chatbot using bot V4 with Direct line channel. I am trying to disable the magic code functionality by following steps mentioned in the bot framework official document (https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication?view=azure-bot-service-4.0).

Unfortunately steps have been specified for C# and Javas script in the official documentation but I am trying to achieve the same by ReactWebChat component.

Sample Code given below :

<ReactWebChat directLine={this.state.directLine} styleOptions={WEBCHAT} User={{ id: 'dl_123', name: 'user_name' }} disabled={!this.state.chatEnabled} locale={this.state.locale} store={store} />

But I am getting following error (error code : 400) : {code: "BadArgument", message: "tokenParameters is missing User."}

It would be great help if you can help me with Reactwebchat code to pass User to directline API (https://directline.botframework.com/v3/directline/conversations)

C# Reference code is given below:

public class HomeController : Controller { public async Task Index() { var secret = GetSecret();

HttpClient client = new HttpClient();

HttpRequestMessage request = new HttpRequestMessage(
    HttpMethod.Post,
    $"https://directline.botframework.com/v3/directline/tokens/generate");

request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secret);

var userId = $"dl_{Guid.NewGuid()}";

request.Content = new StringContent(
    JsonConvert.SerializeObject(
        new { User = new { Id = userId } }),
        Encoding.UTF8,
        "application/json");

var response = await client.SendAsync(request);
string token = String.Empty;

if (response.IsSuccessStatusCode)
{
    var body = await response.Content.ReadAsStringAsync();
    token = JsonConvert.DeserializeObject<DirectLineToken>(body).token;
}

var config = new ChatConfig()
{
    Token = token,
    UserId = userId
};

return View(config);

} }

public class DirectLineToken { public string conversationId { get; set; } public string token { get; set; } public int expires_in { get; set; } } public class ChatConfig { public string Token { get; set; } public string UserId { get; set; } }

fj4870 avatar Jun 12 '20 17:06 fj4870

Closing as this is a duplicate question already posted in BotFramework-Services, here.

stevkan avatar Jun 15 '20 18:06 stevkan