From f185709caddccf337f09ff87e2fe70c7f2dbcd2e Mon Sep 17 00:00:00 2001 From: Marco Zamana Date: Wed, 25 Oct 2023 17:43:56 +0200 Subject: [PATCH 1/2] Update doc about token and samples --- ...ation-connect-bot-to-custom-application.md | 65 +++++++++---------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/power-virtual-agents/publication-connect-bot-to-custom-application.md b/power-virtual-agents/publication-connect-bot-to-custom-application.md index 3257cac49e..0e13d8495c 100644 --- a/power-virtual-agents/publication-connect-bot-to-custom-application.md +++ b/power-virtual-agents/publication-connect-bot-to-custom-application.md @@ -86,27 +86,25 @@ To connect to the bot you have built with Power Virtual Agents, you'll need to r ### Get Direct Line token -To start a conversation with your Power Virtual Agents bot, you need a Direct Line token. You need to add code that retrieves a Direct Line token with the Token Endpoint from the previous section to your app. +To start a conversation with your Power Virtual Agents bot, you need a Direct Line token. This can be obtained by making a GET request to the endpoint indicated within the PVA screen. This token must then be used as the header for subsequent calls to the directline API. -To request a Direct Line token, issue a GET request to the endpoint below: +Example: ```rest-api -GET /api/botmanagement/v1/directline/directlinetoken +GET ``` -| Query Parameter | Required | -| --------------- | -------- | -| `TokenEndPoint` | yes | - - +If the request is successful, will be returned a Direct Line token, expiration time and a conversationId for the requested bot. Example: -```rest-api -GET +```Json +{ + "token": "RCurR_XV9ZA.cwA.BKA.iaJrC8xpy8qbOF5xnR2vtCX7CZj0LdjAPGfiCpg4Fv0y8qbOF5xPGfiCpg4Fv0y8qqbOF5x8qbOF5xn", + "expires_in": 3600, + "conversationId": "abc123" +} ``` -If the request is successful, a Direct Line token will be returned for the requested bot. - #### Sample code example The following example uses samples from the [Connector sample code](https://github.com/microsoft/PowerVirtualAgentsSamples/tree/master/BotConnectorApp) to get a Direct Line token for a Power Virtual Agents bot. @@ -116,21 +114,16 @@ The following example uses samples from the [Connector sample code](https://gith /// Get directline token for connecting bot /// /// directline token as string -public async Task GetTokenAsync() +public async Task GetTokenAsync(string url) { - string token; - using (var httpRequest = new HttpRequestMessage()) - { - httpRequest.Method = HttpMethod.Get; - UriBuilder uriBuilder = new UriBuilder(TokenEndPoint); - httpRequest.RequestUri = uriBuilder.Uri; - using (var response = await s_httpClient.SendAsync(httpRequest)) - { - var responseString = await response.Content.ReadAsStringAsync(); - token = SafeJsonConvert.DeserializeObject(responseString).Token; - } - } - return token; + try + { + return await _httpClient.GetFromJsonAsync(url); + } + catch (HttpRequestException ex) + { + throw ex; + } } ``` @@ -138,18 +131,22 @@ public async Task GetTokenAsync() /// /// class for serialization/deserialization DirectLineToken /// - public class DirectLineToken - { - public string Token { get; set; } - } + public class DirectLineToken +{ + public string Token { get; set; } + public int Expires_in { get; set; } + public string ConversationId { get; set; } +} ``` -The response will be: +The response object will be the same as the GET request we saw earlier ```json - { - "token": "" - } + { + "token": "RCurR_XV9ZA.cwA.BKA.iaJrC8xpy8qbOF5xnR2vtCX7CZj0LdjAPGfiCpg4Fv0y8qbOF5xPGfiCpg4Fv0y8qqbOF5x8qbOF5xn", + "expires_in": 3600, + "conversationId": "abc123" +} ``` ### Use Direct Line to communicate with the bot From 04c21764cd672cabdfa7360334833462c11f43d3 Mon Sep 17 00:00:00 2001 From: Iaan D'Souza-Wiltshire <15990269+iaanw@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:51:15 -0800 Subject: [PATCH 2/2] Update publication-connect-bot-to-custom-application.md --- .../publication-connect-bot-to-custom-application.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/power-virtual-agents/publication-connect-bot-to-custom-application.md b/power-virtual-agents/publication-connect-bot-to-custom-application.md index 0e13d8495c..737bef9744 100644 --- a/power-virtual-agents/publication-connect-bot-to-custom-application.md +++ b/power-virtual-agents/publication-connect-bot-to-custom-application.md @@ -86,7 +86,7 @@ To connect to the bot you have built with Power Virtual Agents, you'll need to r ### Get Direct Line token -To start a conversation with your Power Virtual Agents bot, you need a Direct Line token. This can be obtained by making a GET request to the endpoint indicated within the PVA screen. This token must then be used as the header for subsequent calls to the directline API. +To start a conversation with your bot, you need a Direct Line token. This can be obtained by making a GET request to the endpoint indicated within the Copilot Studio screen. This token must then be used as the header for subsequent calls to the directline API. Example: