Skip to content

Teams Bots

Teams is different from the generated webhook adapters. The Microsoft 365 Agents SDK owns endpoint routing, token validation, activity deserialization, attachments, and proactive conversation endpoints. HPD takes over after the SDK has produced a turn.

Quick Start

csharp
using HPD.Agent.Bots.Teams;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddHPDAgent(options =>
{
    options.ConfigureAgent = agent => agent.WithOpenAI(
        model: builder.Configuration["Agent:Model"]!,
        apiKey: builder.Configuration["OpenAI:ApiKey"]);
});

builder.AddTeamsBot(options =>
{
    options.AppId = builder.Configuration["Teams:AppId"]!;
    options.AppPassword = builder.Configuration["Teams:AppPassword"];
    options.AppTenantId = builder.Configuration["Teams:TenantId"];
    options.AppType = "SingleTenant";
    options.AgentId = builder.Configuration["Agent:Id"] ?? "support-agent";
});

var app = builder.Build();

app.MapTeamsBot();

MapTeamsBot() maps the standard Agents SDK endpoints and the proactive endpoints discovered from Teams continuation handlers.

Configuration

OptionRequiredNotes
AppIdYesMicrosoft Entra app/client id.
AgentIdYesHPD agent definition to run.
AppPasswordOne auth methodClient secret authentication.
Certificate.CertificatePrivateKeyOne auth methodCertificate private key.
Certificate.CertificateThumbprint or Certificate.X5cCertificate authCertificate identity material.
Federated.ClientIdOne auth methodWorkload identity authentication.
Federated.ClientAudienceOptionalDefaults to api://AzureADTokenExchange.
AppTypeOptionalDefaults to MultiTenant; use SingleTenant when appropriate.
AppTenantIdSingle tenantRequired when AppType is SingleTenant.
UserNameOptionalBot display name used for proactive DM creation.

Exactly one auth method should be configured: client secret, certificate, or federated workload identity.

Microsoft 365 Agents SDK Settings

The host app must also provide the Agents SDK auth settings expected by Microsoft.Agents.Hosting.AspNetCore. The exact values depend on your tenant and app registration, but the shape mirrors Microsoft 365 Agents samples:

json
{
  "Teams": {
    "AppId": "<app-client-id>",
    "AppPassword": "<client-secret>",
    "TenantId": "<tenant-id>"
  },
  "TokenValidation": {
    "Enabled": true,
    "Audiences": ["<app-client-id>"],
    "TenantId": "<tenant-id>"
  },
  "AgentApplication": {
    "StartTypingTimer": false,
    "RemoveRecipientMention": false,
    "NormalizeMentions": false
  },
  "Connections": {
    "ServiceConnection": {
      "Settings": {
        "AuthType": "ClientSecret",
        "AuthorityEndpoint": "https://login.microsoftonline.com/<tenant-id>",
        "ClientId": "<app-client-id>",
        "ClientSecret": "<client-secret>",
        "Scopes": ["https://api.botframework.com/.default"]
      }
    }
  },
  "ConnectionsMap": [
    {
      "ServiceUrl": "*",
      "Connection": "ServiceConnection"
    }
  ]
}

Use the Teams Toolkit or Teams CLI workflow to create/sideload the app and verify endpoint reachability. HPD does not currently document arbitrary custom Teams endpoint aliases; use app.MapTeamsBot().

Capabilities

AreaHPD Teams behavior
Inbound messagesRun the configured HPD agent.
StreamingNative Teams output path.
FilesFile uploads can be downloaded through M365 attachment downloaders and surfaced as HPD input files.
CardsAdaptive Cards.
Card actionsSupported through Teams action handling.
PermissionsApprove/Deny card actions use hpd.permission.approve and hpd.permission.deny.
ReactionsReceiving reactions is supported; adding/removing reactions is not.
HistoryGraph-backed history is opt-in.

Graph History

Register Graph history only when the host already has a configured GraphServiceClient:

csharp
builder.Services.AddTeamsGraphHistory(graphClient);

Graph-backed history uses Teams-specific fetch/list options and requires the tenant/app permissions your Graph client needs. Validate Graph permissions in the target tenant before promising history behavior to users.

Troubleshooting

SymptomCheck
UnauthorizedClient secret/certificate/federated identity is wrong or expired.
Single-tenant auth failsAppTenantId is missing or does not match the app registration.
Messages do not reach HPDAgents SDK TokenValidation, Connections, or ConnectionsMap is missing; app is not installed; endpoint is not public.
File uploads missingM365 attachment downloaders or service permissions are not configured.
Graph history unavailableAddTeamsGraphHistory(...) was not registered or Graph permissions are missing.

Built for production .NET agent applications.