microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
cg/sovereign-cloud-nextcore

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/test/msal-config-api/Program.cs

59lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Extensions.Configuration;
5using Microsoft.Extensions.DependencyInjection;
6using Microsoft.Extensions.Logging;
7using Microsoft.Teams.Bot.Core;
8using Microsoft.Teams.Bot.Core.Hosting;
9using Microsoft.Teams.Bot.Core.Schema;
10
11
12string ConversationId = "a:17vxw6pGQOb3Zfh8acXT8m_PqHycYpaFgzu2mFMUfkT-h0UskMctq5ZPPc7FIQxn2bx7rBSm5yE_HeUXsCcKZBrv77RgorB3_1_pAdvMhi39ClxQgawzyQ9GBFkdiwOxT";
13string FromId = "28:56653e9d-2158-46ee-90d7-675c39642038";
14string ServiceUrl = "https://smba.trafficmanager.net/teams/";
15
16ConversationClient conversationClient = CreateConversationClient();
17await conversationClient.SendActivityAsync(new CoreActivity
18{
19 Conversation = new() { Id = ConversationId },
20 ServiceUrl = new Uri(ServiceUrl),
21 From = new() { Id = FromId },
22 Properties = { { "text", "Test Message" } }
23
24
25}, cancellationToken: default);
26
27await conversationClient.SendActivityAsync(new CoreActivity
28{
29 //Text = "Hello from MSAL Config API test!",
30 Conversation = new() { Id = "bad conversation" },
31 ServiceUrl = new Uri(ServiceUrl),
32 From = new() { Id = FromId }
33
34}, cancellationToken: default);
35
36
37
38static ConversationClient CreateConversationClient()
39{
40 ServiceCollection services = InitializeDIContainer();
41 services.AddConversationClient();
42 ServiceProvider serviceProvider = services.BuildServiceProvider();
43 ConversationClient conversationClient = serviceProvider.GetRequiredService<ConversationClient>();
44 return conversationClient;
45}
46
47static ServiceCollection InitializeDIContainer()
48{
49 IConfigurationBuilder builder = new ConfigurationBuilder()
50 .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
51 .AddEnvironmentVariables();
52
53 IConfiguration configuration = builder.Build();
54
55 ServiceCollection services = new();
56 services.AddSingleton(configuration);
57 services.AddLogging(configure => configure.AddConsole());
58 return services;
59}
60