Skip to main content

Notifications

Copilot Studio - Publish & Channel Management
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.

  • adilei Profile Picture
    adilei on at
    Re: I wanted to end the chatbot session manually

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

  • Karishma2805998 Profile Picture
    Karishma2805998 71 on at
    Re: I wanted to end the chatbot session manually

    @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
    adilei on at
    Re: I wanted to end the chatbot session manually

    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
    Karishma2805998 71 on at
    Re: I wanted to end the chatbot session manually

    Was the above code snippet shared was helpful adilei?

  • Karishma2805998 Profile Picture
    Karishma2805998 71 on at
    Re: I wanted to end the chatbot session manually

    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

     

  • adilei Profile Picture
    adilei on at
    Re: I wanted to end the chatbot session manually

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

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,526

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard

Featured topics