0

I have a chatbot created using react webchat botframework. I understand after an hour the token expires and cannot be refreshed but my issue is that the conversation seems to restart after 30 minutes.

So i refresh the token within 1 hour and get a 200 response that the token is refreshed. If its within 30 minutes of the conversation original start then I can continue the conversation as expected. If it is over 30 minutes then I will see the conversation history but then it will restart from the beginning and I will see the first message.

Not sure where the issue lies or what information I can provide or how to troubleshoot so please let me know if you have any clue on how to fix this.

EDIT: Im wondering if this is possibly related to the userID. If I try to set the userID in the react component I get the message "connectSaga.js:58 Web Chat: user ID is both specified in the Direct Line token and passed in, will use the user ID from the token"

How does the user ID get set in the token? How can it be modified?

1 Answers1

0

First, regarding the userID, it can be defined in either the request to the DirectLine service that generates the token or in the Web Chat rendering component as a property. As you have seen in the warning, Web Chat defaults to the userID defined with the token request. It does this for a few reasons, two being security and eliminating two differently defined userIDs from being utilized.

To 'bake' the userID into the token, it is sent in the request's body, as defined here. Here's an example:

{
    "user": {
        "id": "dl_abc123",
        "name": "Steve",
        "role": "user"
    }
}

As for the conversation restarting, with Web Chat you don't need to manually refresh the token. Web Chat takes care of this for you by refreshing it every 15 mins. You can see this here in the BotFramework-DirectLineJS repo, which is a dependency of Web Chat. It's possible that your refreshing and Web Chat refreshing is somehow colliding. Disable/remove your refresh token implementation and try relying on Web Chat alone to take care of is. See if this makes a difference.

If it doesn't, then I would suggest you try implementing persistence in your Web Chat hosting page. This will allow you to reload the page or navigate away and come back without losing the conversation. You can follow the instructions in this SO response on how to set this up.

Steven Kanberg
  • 6,078
  • 2
  • 16
  • 35
  • Hello, thanks for you useful response. I removed the token refresh but it doesnt look to have made any difference. Also I didnt mention that we are using a chatbot designed in PVA so we are requesting the token from the below url which only supports a GET method: https://va.ai.dynamics.com/api/botmanagement/v1/directline/directlinetoken?botId=&tenantId= Any further help and suggestions would be greatly appreciated :) – user19600695 Aug 05 '22 at 09:12
  • Did you try the implementing persistence, as suggested in the last paragraph? Also, which version of Web Chat are you using (I'm assuming the latest)? – Steven Kanberg Aug 09 '22 at 21:39