Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions samples/SocketModeBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@

// Socket Mode receives activities over an outbound WebSocket, so the bot runs on a
// generic host with no web server and no public messaging endpoint.
// Socket Mode is currently only available for new bots.
HostApplicationBuilder builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings
{
Args = args,
ContentRootPath = AppContext.BaseDirectory,
});
builder.Services.AddTeamsBotApplication(options => options.UseSocketMode(socket =>
{
// Socket Mode is only available on the Canary and Pilot1 rings for now.
// Pilot1 (https://pilot1.botapi.skype.com) is supported as well.
socket.NegotiateBaseUrl = new Uri("https://canary.botapi.skype.com");
}));
builder.Services.AddTeamsBotApplication(options => options.UseSocketMode());
using IHost host = builder.Build();

TeamsBotApplication teamsApp = host.UseTeamsBotApplication();
Expand Down
3 changes: 2 additions & 1 deletion samples/SocketModeBot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ This sample is an echo bot that receives activities over Socket Mode instead of

## What it shows

- `UseSocketMode(...)` on `AddTeamsBotApplication` to receive activities over Socket Mode, with `NegotiateBaseUrl` set to the canary ring. Socket Mode is currently only available on the Canary (`https://canary.botapi.skype.com`) and Pilot1 (`https://pilot1.botapi.skype.com`) rings.
- `UseSocketMode()` on `AddTeamsBotApplication` to receive activities over Socket Mode using the default production endpoint (`https://botapi.skype.com`).
Comment thread
teddyam marked this conversation as resolved.
Resolved
- One connection per geo (`amer`, `emea`, `apac`) by default for inbound coverage across regions. Override with `Geos = [...]` or point at a custom ring with `NegotiateBaseUrl` in the `UseSocketMode(socket => ...)` callback.
- `<NoWarn>$(NoWarn);ExperimentalTeamsSocketMode</NoWarn>` in the project file, because Socket Mode is experimental.
- A generic host (`Host.CreateApplicationBuilder`) with no web server, and `UseTeamsBotApplication()` to get the app.
- Per-geo `Ready`, `Disconnected`, and `Reconnected` subscriptions in `Program.cs`, plus a status snapshot after startup.
Expand Down
3 changes: 0 additions & 3 deletions src/Microsoft.Teams.Apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ host.Run();
- **Public cloud only** &mdash; Registration fails for bots configured for another cloud.
- **Classic bot identity only** &mdash; The connection is negotiated with the bot's app ID and credentials. Agentic
identities are not supported.
- **Canary and Pilot1 endpoints** &mdash; Socket Mode is currently available only on the Canary and Pilot1 rings. Set
`NegotiateBaseUrl` to `https://canary.botapi.skype.com` or `https://pilot1.botapi.skype.com` until it is enabled on
the default production endpoint.
- **Rejected credentials are not retried** &mdash; If negotiation returns HTTP 401 or 403, startup fails immediately.
After startup, the affected geo stops reconnecting until the app restarts.
- **Throttling respects the service** &mdash; On HTTP 429, the service's `Retry-After` delay takes precedence over
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.Teams.Apps/SocketMode/SocketModeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ namespace Microsoft.Teams.Apps.SocketMode;
/// It is supported only in the public cloud, and runs on a host without a web server
/// (<c>Host.CreateApplicationBuilder</c>). Settings are validated when the host starts.
/// Socket Mode is experimental: the API is in preview and may change, and it is recommended only for developing agents.
/// Socket Mode is currently only available for new bots.
/// </remarks>
[Experimental("ExperimentalTeamsSocketMode")]
public sealed class SocketModeOptions
{
/// <summary>
/// Gets or sets the base URL used to negotiate each geo connection. Must use HTTPS unless it targets loopback.
/// Defaults to <c>https://botapi.skype.com</c>.
/// Defaults to <c>https://botapi.skype.com</c>. Override this to target a different Teams backend service ring.
/// </summary>
public Uri NegotiateBaseUrl { get; set; } = new(SocketModeProtocol.DefaultNegotiateBaseUrl);

/// <summary>
/// Gets or sets the geos to connect, one connection each. An empty string connects to the base URL without a geo
/// segment. Defaults to <c>amer</c>, <c>emea</c>, and <c>apac</c>.
/// segment. Defaults to <c>amer</c>, <c>emea</c>, and <c>apac</c>. Override this to connect to a different set of geos.
/// </summary>
public IReadOnlyList<string> Geos { get; set; } = SocketModeProtocol.DefaultGeos;

Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.Teams.Apps/TeamsBotApplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public TeamsBotApplicationOptions UseState(Action<TurnStateOptions>? configure =
/// get the app with <c>host.UseTeamsBotApplication()</c>. Passing <see langword="false"/> clears any earlier Socket
/// Mode configuration, so the bot receives activities over HTTP. Socket Mode is experimental: the API is in preview
/// and may change, and it is recommended only for developing agents.
/// Socket Mode is currently only available for new bots.
/// </remarks>
/// <param name="enabled">Whether to receive activities over Socket Mode. Default is <see langword="true"/>.</param>
/// <returns>This instance for chaining.</returns>
Expand All @@ -94,6 +95,7 @@ public TeamsBotApplicationOptions UseSocketMode(bool enabled = true)
/// Supported only in the public cloud. Build the bot with <c>Host.CreateApplicationBuilder()</c> (no web server) and
/// get the app with <c>host.UseTeamsBotApplication()</c>. Socket Mode is experimental: the API is in preview and may
/// change, and it is recommended only for developing agents.
/// Socket Mode is currently only available for new bots.
/// </remarks>
/// <param name="configure">Delegate to configure <see cref="SocketModeOptions"/>.</param>
/// <returns>This instance for chaining.</returns>
Expand Down
Loading