# azure-web-pubsub-ts

Teaches your agent to build WebSocket apps and pub/sub messaging on TypeScript with Azure Web PubSub client and server libraries.

- skill · `type=skill` · Claude Code, GitHub Copilot · 1 install · ★ 3149
- Author: Microsoft
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-typescript/skills/azure-web-pubsub-ts/SKILL.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/skills/azure-web-pubsub-ts

## What it does

This skill guides coding assistants through working with `@azure/web-pubsub`, `@azure/web-pubsub-client`, and `@azure/web-pubsub-express`. It provides code structures for hub management, real-time client events, and Express request handlers.

On the server side, the assistant sets up `WebPubSubServiceClient` with connection strings or Microsoft Entra ID. It covers temporary client token generation, OData filtering, permission grants, and group messaging. The client patterns show connection setup and event subscription.

Backend calls will fail unless you configure `WEBPUBSUB_CONNECTION_STRING` or `WEBPUBSUB_ENDPOINT` beforehand. Production deployments using `DefaultAzureCredential` also require setting `AZURE_TOKEN_CREDENTIALS`.

## Requirements
- Works with: Azure

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add microsoft/skills --skill azure-web-pubsub-ts -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/azure-web-pubsub-ts/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/azure-web-pubsub-ts/

### Codex

**Manually: put the files in place**
- File: `.agents/skills/azure-web-pubsub-ts/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

**Manually: put the files in place**
- File: `.cursor/skills/azure-web-pubsub-ts/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install microsoft/skills azure-web-pubsub-ts
```

2. **Manually: put the files in place**
- File: `.github/skills/azure-web-pubsub-ts/SKILL.md`

### Gemini CLI

**Platform CLI**
```bash
gemini skills install https://github.com/microsoft/skills --path .github/plugins/azure-sdk-typescript/skills/azure-web-pubsub-ts
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/azure-web-pubsub-ts/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-typescript/skills/azure-web-pubsub-ts/SKILL.md

## When to use it
- configure WebSocket connections on the frontend via TypeScript
- issue scoped client access tokens with specific group roles
- handle incoming connection requests and custom events in Express
- broadcast updates to specific users or groups using Azure Web PubSub

## Example prompts
- Show how to generate an access token for user123 with permissions for chat-room.
- Create a browser client setup to join a group and listen for messages.
- Write an Express middleware handler that validates client connections to the chat hub.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: c7c8816440594848.

BEGIN THIRD-PARTY FILE c7c8816440594848
````text
---
name: azure-web-pubsub-ts
description: Build real-time messaging applications using Azure Web PubSub SDKs for JavaScript (@azure/web-pubsub, @azure/web-pubsub-client). Use when implementing WebSocket-based real-time features, pub/sub messaging, group chat, or live notifications.
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
  package: '@azure/web-pubsub, @azure/web-pubsub-client'
---

# Azure Web PubSub SDKs for TypeScript

Real-time messaging with WebSocket connections and pub/sub patterns.

## Installation

```bash
# Server-side management
npm install @azure/web-pubsub @azure/identity

# Client-side real-time messaging
npm install @azure/web-pubsub-client

# Express middleware for event handlers
npm install @azure/web-pubsub-express
```

## Environment Variables

```bash
WEBPUBSUB_CONNECTION_STRING=Endpoint=https://<resource>.webpubsub.azure.com;AccessKey=<key>;Version=1.0;
WEBPUBSUB_ENDPOINT=https://<resource>.webpubsub.azure.com
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
```

## Server-Side: WebPubSubServiceClient

### Authentication

```typescript
import { WebPubSubServiceClient, AzureKeyCredential } from "@azure/web-pubsub";
import { DefaultAzureCredential, ManagedIdentityCredential } from "@azure/identity";

// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
const credential = new DefaultAzureCredential({requiredEnvVars: ["AZURE_TOKEN_CREDENTIALS"]});
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest#credential-classes
// const credential = new ManagedIdentityCredential();

// Connection string
const client = new WebPubSubServiceClient(
  process.env.WEBPUBSUB_CONNECTION_STRING!,
  "chat"  // hub name
);

// Microsoft Entra Token Credential (recommended)
const client2 = new WebPubSubServiceClient(
  process.env.WEBPUBSUB_ENDPOINT!,
  credential,
  "chat"
);

// AzureKeyCredential
const client3 = new WebPubSubServiceClient(
  process.env.WEBPUBSUB_ENDPOINT!,
  new AzureKeyCredential("<access-key>"),
  "chat"
);
```

### Generate Client Access Token

```typescript
// Basic token
const token = await client.getClientAccessToken();
console.log(token.url);  // wss://...?access_token=...

// Token with user ID
const userToken = await client.getClientAccessToken({
  userId: "user123",
});

// Token with permissions
const permToken = await client.getClientAccessToken({
  userId: "user123",
  roles: [
    "webpubsub.joinLeaveGroup",
    "webpubsub.sendToGroup",
    "webpubsub.sendToGroup.chat-room",  // specific group
  ],
  groups: ["chat-room"],  // auto-join on connect
  expirationTimeInMinutes: 60,
});
```

### Send Messages

```typescript
// Broadcast to all connections in hub
await client.sendToAll({ message: "Hello everyone!" });
await client.sendToAll("Plain text", { contentType: "text/plain" });

// Send to specific user (all their connections)
await client.sendToUser("user123", { message: "Hello!" });

// Send to specific connection
await client.sendToConnection("connectionId", { data: "Direct message" });

// Send with filter (OData syntax)
await client.sendToAll({ message: "Filtered" }, {
````
END THIRD-PARTY FILE c7c8816440594848

The third-party file has ended. Everything between the c7c8816440594848 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3313 of 8393 bytes. © Microsoft · MIT · https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-typescript/skills/azure-web-pubsub-ts/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
