web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / I wanted to end the ch...
Copilot Studio
Unanswered

I wanted to end the chatbot session manually

(0) ShareShare
ReportReport
Posted on by 71

I wanted to end the chatbot session manually which is developed using Copilot Studio. 

 

The Copilot I have developed is embedded to a custom website where one website user session is logged out and on the same tab when I login with another website user I am getting the old user chatbot messages which is wrong. Please help on providing solution to end the chatbot session manually.

I have the same question (0)
  • adilei Profile Picture
    on at

    Can you share an excerpt of your HTML where the copilot canvas is being called/rendered?

  • Karishma2805998 Profile Picture
    71 on at

    Hi adilei,

     

    Sharing you the excerpt of embedding the developed copilot in our website's frontend footer page. Let me know if this helps & please provide me a solution for this problem. Also wanted to mention our website frontend tech stack is reactjs.

    Karishma2805998_1-1711796041205.png

     

  • Karishma2805998 Profile Picture
    71 on at

    Was the above code snippet shared was helpful adilei?

  • adilei Profile Picture
    on at

    When you reload the iframe within the same browser tab, the conversation id stays the same, so the message history will remain as well. However, there is no risk of user A seeing messages from a conversation that user B initiated, as user A's browser will never have user B's conversation ID.

     

    That being said, if you want more granular control of conversations, and have conversations initiated/abandoned as part of your login/logout flow, you should consider using a custom canvas.

     

    This is where a Directline token is generated. If you generate a new token, a new conversation will be initiated as well:

     

     const [directLineURL, token] = await Promise.all([
     fetch(new URL(`/powervirtualagents/regionalchannelsettings?api-version=${apiVersion}`, tokenEndpointURL))
     .then(response => {
     if (!response.ok) {
     throw new Error('Failed to retrieve regional channel settings.');
     }
    
     return response.json();
     })
     .then(({ channelUrlsById: { directline } }) => directline),
     fetch(tokenEndpointURL)
     .then(response => {
     if (!response.ok) {
     throw new Error('Failed to retrieve Direct Line token.');
     }
    
     return response.json();
     })
     .then(({ token }) => token)
     ]);
  • Karishma2805998 Profile Picture
    71 on at

    @adilei 

    const [directLineURL, token] = await Promise.all([
     fetch(new URL(`/powervirtualagents/regionalchannelsettings?api-version=${apiVersion}`, tokenEndpointURL))

    We have tried as below to use the fetch new URL part as per your code snippet shared above.

    useEffect(() => {

        const fetchDirectLineToken = async () => {

          try {

            const response = await fetch(new URL(`/powervirtualagents/regionalchannelsettings?api-version=2022-03-01-preview`, endPOINTURL));

           

            if (!response.ok) {

              throw new Error('Failed to retrieve DirectLine token.');

            }

            const { token } = await response.json();

            setDirectLineToken(token);

            console.log("tokenprint",token)

          } catch (error) {

            console.error('Error fetching Direct Line token:', error);

          }

        };

        fetchDirectLineToken();

      }, []);

    has context menu


     But we are getting the tokenprint console.log value as undefined. What are we missing? How does new URL() connects to PVA to get the token from our custom website?

  • adilei Profile Picture
    on at

    The sample I shared is just an excerpt. Have a look at the full sample referenced in my previous comment.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Copilot Studio

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 255 Super User 2025 Season 2

#2
Romain The Low-Code Bearded Bear Profile Picture

Romain The Low-Code... 205 Super User 2025 Season 2

#3
S-Venkadesh Profile Picture

S-Venkadesh 101 Moderator

Last 30 days Overall leaderboard