microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/test/msal-config-api/Program.cs
59lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Extensions.Configuration; |
| 5 | using Microsoft.Extensions.DependencyInjection; |
| 6 | using Microsoft.Extensions.Logging; |
| 7 | using Microsoft.Teams.Bot.Core; |
| 8 | using Microsoft.Teams.Bot.Core.Hosting; |
| 9 | using Microsoft.Teams.Bot.Core.Schema; |
| 10 | |
| 11 | |
| 12 | string ConversationId = "a:17vxw6pGQOb3Zfh8acXT8m_PqHycYpaFgzu2mFMUfkT-h0UskMctq5ZPPc7FIQxn2bx7rBSm5yE_HeUXsCcKZBrv77RgorB3_1_pAdvMhi39ClxQgawzyQ9GBFkdiwOxT"; |
| 13 | string FromId = "28:56653e9d-2158-46ee-90d7-675c39642038"; |
| 14 | string ServiceUrl = "https://smba.trafficmanager.net/teams/"; |
| 15 | |
| 16 | ConversationClient conversationClient = CreateConversationClient(); |
| 17 | await 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 | |
| 27 | await 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 | |
| 38 | static 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 | |
| 47 | static 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 | |