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 / API integration witn P...
Copilot Studio
Unanswered

API integration witn Power Virtual Agent Chat bot

(0) ShareShare
ReportReport
Posted on by

Hi, 

 

We created an PVA Chat bot and we would like to integrate the chat bot in an application.

Is there an API we can use because all i found in channel is the use of an iframe but this does not match our requirements.

 

Thank you

Categories:
I have the same question (0)
  • HenryJammes Profile Picture
    on at

    Hi @kmoens,

     

    Yes, that would be the Direct Line API: API reference - Direct Line API 3.0 - Bot Service | Microsoft Learn

     

    Henry

  • Community Power Platform Member Profile Picture
    on at

    Hi, thank you.

     

    Can i find some examples somewhere how to start the conversation ?

     

  • Verified answer
    HenryJammes Profile Picture
    on at

    Sure @kmoens,

     

    I'll break it down to you below. These are basic examples, please refer to the documentation to learn more about all the options and parameters you can use. The Direct Line endpoints may also be different by region, but this is also documented. 

     

    #1 Generate a Direct Like Token:

     

    The first thing you want to do is generating a Direct Line token for the conversation.

    You can get it under Settings > Channels, in "Mobile App":

    HenryJammes_0-1698317174695.png

     

    So just do a GET on the URL, and it will return the token as well as a conversationid.

     

    E.g. in Postman for my test bot endpoint: 

     

    https://c53bf00279234d1cb5ae3265093d59.e1.environment.api.powerplatform.com/powervirtualagents/botsbyschema/cr507_testChatbot/directline/token?api-version=2022-03-01-preview

     

    HenryJammes_1-1698317374474.png

     

     

    #2 Initiate Conversation

     

    Then, still using Bearer Token authentication with the retrieved token in step #1, do a POST on:

     

    https://directline.botframework.com/v3/directline/conversations

     

    This will also return the streamUrl if you want to use WebSocket (Receive activities from the bot - Bot Service | Microsoft Learn)

     

    E.g. in Postman:

    HenryJammes_2-1698317574018.png

     

    #3 Send startConversation event

     

    You can trigger the automatic start of the conversation by sending the startConversation event

    Here, still using Bearer Token authentication with the retrieved token in step #1, do a POST on this URL.
    Notice that now you also need to pass the conversationId in the URL:

     

     

    https://directline.botframework.com/v3/directline/conversations/{{ConversationId}}/activities

     

    In the body, send:

     

    {
     "type": "event",
     "name": "startConversation"
    }

     

     

    E.g. in Postman:

    HenryJammes_3-1698317794797.png

     

    #4 Send message

     

    To send a message, still using Bearer Token authentication with the retrieved token in step #1, and still with the conversationId, do a POST on this URL:

     

    https://directline.botframework.com/v3/directline/conversations/{{ConversationId}}/activities

     

     

     

     

    In the body, send:

     

    {
     "type": "message",
     "text": "When are you closed"
    }

     

     

    E.g. in Postman:

    HenryJammes_4-1698317938565.png

     

    #5 Get responses

     

    You can return all the chatbot activities (send and received messages), still using Bearer Token authentication with the retrieved token in step #1, and still with the conversationId. Do a GET on this URL:

     

    https://directline.botframework.com/v3/directline/conversations/{{ConversationId}}/activities

     

     

    E.g. in Postman:

    HenryJammes_5-1698318097367.png

     

    Let me know if this helps

    Henry

     

     

     

  • Community Power Platform Member Profile Picture
    on at

    Hi Henry,

     

    This is perfect !!!

     

    Thank you so much

  • HenryJammes Profile Picture
    on at

    Awesome, great to see this is helpful @kmoens! Feel free to also accept my post as the solution 

  • soundharya Profile Picture
    249 on at

    Thank you Henry, this is really helpful!

    This works fine when security is set to None, do you have any idea or tried on how to do for SSO login or for manual authentication? 

  • adilei Profile Picture
    on at

    When manual authentication is configured, Copilot Studio will send a sign-in request activity when the sign-in topic is triggered. Your client should obtain an access token for a user that is signed-in and send it over Directline. The pattern is similar to the client-side logic here: CopilotStudioSamples/BuildYourOwnCanvasSamples/3.single-sign-on/index.html at master · microsoft/CopilotStudioSamples (github.com)

     

     

  • JohanT Profile Picture
    35 on at

    According to https://learn.microsoft.com/en-us/microsoft-copilot-studio/advanced-end-user-authentication?tabs=web#useraccesstoken you should supply User.AccessToken. I'm using the rest api, and it is a bit unclear how to do it. I guess the bearer token in the header still is reserved for the directLineSecret? Should i supply it in a body? If so what key should I use? Also, is there any documentation for this. I'm making a nativ iOS app, and most documentations seems to be about web.

  • adilei Profile Picture
    on at

    Maybe start a new thread? You can tag me there. 

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