forked from microsoft/CopilotStudioSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (47 loc) · 2.12 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (47 loc) · 2.12 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
55
56
57
using Microsoft.Agents.Builder;
using Microsoft.Agents.CopilotStudio.Client;
using Microsoft.Agents.Hosting.AspNetCore;
using Microsoft.Extensions.Options;
using HandoverToLiveAgent.LiveChat;
using Microsoft.Agents.CopilotStudio;
using HandoverToLiveAgent.CopilotStudio;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.ListenAnyIP(5001);
});
builder.Services.AddScoped<ILiveChatService, LiveChatService>();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddHttpClient();
// Add services to the container.
builder.Services.AddSingleton<IConversationManager, ConversationManager>();
builder.Services.AddSingleton<IProactiveMessenger, MsTeamsProactiveMessage>();
// Agents SDK setup
builder.AddAgentApplicationOptions();
builder.AddAgent<HandoverToLiveAgent.CopilotStudio.CopilotStudioAgent>();
// Agents storage for conversation state
builder.Services.AddSingleton<Microsoft.Agents.Storage.IStorage, Microsoft.Agents.Storage.MemoryStorage>();
// Ensure AgentApplicationOptions is available for AgentApplication-based skills
builder.Services.AddSingleton<Microsoft.Agents.Builder.App.AgentApplicationOptions>();
var app = builder.Build();
// Only enforce HTTPS when an HTTPS binding is configured (avoid warnings when running HTTP-only locally)
var hasHttpsBinding =
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("HTTPS_PORTS")) ||
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("ASPNETCORE_HTTPS_PORT")) ||
builder.Configuration.GetSection("Kestrel:Endpoints:Https").Exists();
if (!app.Environment.IsDevelopment() && hasHttpsBinding)
{
app.UseHttpsRedirection();
}
app.UseStaticFiles();
app.UseDefaultFiles();
app.UseRouting();
app.MapControllers();
// Agents endpoint: /api/messages for incoming messages and activities from Copilot Studio skills
var incomingRoute = app.MapPost("/api/messages", async (HttpRequest request,
HttpResponse response, IAgentHttpAdapter adapter, IAgent agent, CancellationToken ct) =>
{
await adapter.ProcessAsync(request, response, agent, ct);
});
app.Run();