Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

UserId not propagating from DirectLineJS to Azure Log Analytics #6588

Description

@adolfo1981

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Version

  • For Frontend (Angular App): Using DirectLineJS version 0.15.1
  • For Backend App using following packages:
        <PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.19.3" />
        <PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.19.3" />
        <PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.19.3" />

Describe the bug

I have an angular application that uses DirectLineJS and connects to an Azure Bot (net 6 app) to get a Token and start conversation with a bot.

This is how I'm getting the token from the Angular App:

getToken(iframeQueryParams: IFrameQueryParams): Observable<FCChatTokenDTO> {
    return this.http.get<FCChatTokenDTO>(
      `${environment.fcChatbotAPIUrl}/api/token?userId=${iframeQueryParams.userId}&divisionId=${iframeQueryParams.divisionId}`
    );
  }

And this is the method I use to send message to the bot:

  sendMessage(text: string) {
    const msg = {
      from: { id: this.userId, name: 'Test name' },
      type: 'message',
      text,
    } as FCChatMessage;
    return this.directline.postActivity(msg);
  }

this.userId variable is set to a user following direct line convention starting with dl_ prefix. Something like dl_123456

When I navigate to my Log Analytics Workspace and query for question & answer data like this:

// All QnA Traffic
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.COGNITIVESERVICES"
| where OperationName=="CustomQuestionAnswering QueryKnowledgebases" // This OperationName is valid for custom question answering enabled resources
| sort by TimeGenerated desc

I get the following properties. Notice userId is empty:

{
"kbId": "FCKB",
"userId": "",
"question": "how do I create an account?",
"id": "2609",
"answer": "To create a deduction code for a health savings account (HSA), go to the SETUP tab > Payroll > Payroll Deductions. Click Add. Click the Add button for Health Savings Account (Single) or Health Savings Account (Family). Click OK in the confirmation window. Click the X in the top-right corner to close the Add Deduction panel. To make changes, click the Edit icon (pencil) next to the new code, and make your changes. \n\nThe Health Savings Account (Single) or Health Savings Account (Family) code is used for a pre-tax flat amount deduction of an employee's wages that they can opt-in to set aside to go into an HSA, which can pay for certain qualified medical expenses, such as copayments, deductibles, etc. For the Family option, the taxable wage limit is per family.",
"score": "68.37",
"source": "Q&As for earnings and deductions for FCKB.xlsx",
"isQnaOverDocumentRequest": "True",
"isAnswerFromDocumentText": "Microsoft.CognitiveServices.QnAMaker.Runtime.Models.QnASearchResult",
"azure-Resource-Id": "/subscriptions/XXXXXXXXXXX/resourcegroups/qna-bot-dev/providers/microsoft.cognitiveservices/accounts/fc-bot-language",
"apim-request-id": "XXXXXXXXX"
}

This is the method I use in my Azure Bot dotnet 6 app:

        public async Task<ActionResult<ChatConfig>> token([FromQuery] string? userId,[FromQuery] int? divisionId)
        {
            if (!string.IsNullOrWhiteSpace(_configuration["DirectLineSecret"]))
            {
                _DirectLineSecret = _configuration["DirectLineSecret"];
            }

            HttpClient client = new HttpClient();

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

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

            if(string.IsNullOrEmpty(userId))
            {
                userId = Guid.NewGuid().ToString();
            }

            if (divisionId == null)
            {
                divisionId = 0;
            }

            //Important: User Id value needs to start with dl_ prefix, otherwise request will fail with 401
            var userParam = $"dl_u_{userId}_d_{divisionId}";

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

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

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

            var config = new ChatConfig()
            {
                token = token,
                userId = userParam,
                conversationId = conversationId
            };

            return Ok(config);
        }

Expected behavior

I would expect userId to be populated in the result of my kusto query since I'm generating a token passing a correct userId and also passing the user id via the directLine.postActivity function. Why is userId not being populated?

Activity

  1. added
    bugIndicates an unexpected problem or an unintended behavior.
    needs-triageThe issue has just been created and it has not been reviewed by the team.
    on Apr 12, 2023
  2. self-assigned this
    on Apr 21, 2023
  3. ram-xv commented on Apr 21, 2023

    @ram-xv
    Contributor

    Thanks for reporting this issue adolfo1981, I'm investigating this issue.

  4. added
    Bot ServicesRequired for internal Azure reporting. Do not remove. Do not change color.
    customer-reportedIssue is created by anyone that is not a collaborator in the repository.
    and removed
    needs-triageThe issue has just been created and it has not been reviewed by the team.
    on Apr 21, 2023
  5. adolfo1981 commented on Apr 21, 2023

    @adolfo1981
    Author
  6. sw-joelmut commented on Apr 24, 2023

    @sw-joelmut

    Hi @ramfattah, we were able to reproduce the issue.
    If it's ok, we'll continue working on fixing the issue.

    Thanks!

  7. ram-xv commented on Apr 24, 2023

    @ram-xv
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bot ServicesRequired for internal Azure reporting. Do not remove. Do not change color.bugIndicates an unexpected problem or an unintended behavior.customer-reportedIssue is created by anyone that is not a collaborator in the repository.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions