forked from microsoft/CopilotStudioSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBotService.cs
More file actions
54 lines (45 loc) · 1.64 KB
/
Copy pathBotService.cs
File metadata and controls
54 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.Rest.Serialization;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace Microsoft.PowerVirtualAgents.Samples.RelayBotSample
{
/// <summary>
/// Bot Service class to interact with bot
/// </summary>
public class BotService : IBotService
{
private static readonly HttpClient s_httpClient = new HttpClient();
public string BotName { get; set; }
public string BotId { get; set; }
public string TenantId { get; set; }
public string TokenEndPoint { get; set; }
public string GetBotName()
{
return BotName;
}
/// <summary>
/// Get directline token for connecting bot
/// </summary>
/// <returns>directline token as string</returns>
public async Task<string> GetTokenAsync()
{
string token;
using (var httpRequest = new HttpRequestMessage())
{
httpRequest.Method = HttpMethod.Get;
UriBuilder uriBuilder = new UriBuilder(TokenEndPoint);
uriBuilder.Query = $"botId={BotId}&tenantId={TenantId}";
httpRequest.RequestUri = uriBuilder.Uri;
using (var response = await s_httpClient.SendAsync(httpRequest))
{
var responseString = await response.Content.ReadAsStringAsync();
token = SafeJsonConvert.DeserializeObject<DirectLineToken>(responseString).Token;
}
}
return token;
}
}
}