# What Is the Default Heartbeat Interval for CloddsBot WebSocket?

> Discover the default WebSocket heartbeat interval for CloddsBot. Learn how it's set and when to customize it for your application.

- Repository: [AL/CloddsBot](https://github.com/alsk1992/CloddsBot)
- Tags: faq
- Published: 2026-09-13

---

**The default WebSocket heartbeat interval for CloddsBot is 45 seconds (45,000 milliseconds), hardcoded as a fallback in [`src/gateway/index.ts`](https://github.com/alsk1992/CloddsBot/blob/main/src/gateway/index.ts) when the configuration object does not specify a custom value.**

WebSocket connections in CloddsBot rely on periodic heartbeat signals to detect connection health and prevent timeouts. According to the source code in the `alsk1992/CloddsBot` repository, the gateway automatically applies this 45-second interval unless explicitly overridden through the configuration object.

## Where the Default Heartbeat Interval Is Defined

In the gateway initialization logic, the heartbeat interval resolves using the nullish coalescing operator to guarantee a fallback value:

```typescript
// src/gateway/index.ts (line 144)
heartbeatInterval: config.heartbeatInterval ?? 45000,

```

This implementation ensures that if `config.heartbeatInterval` is `undefined` or `null`, the gateway immediately defaults to `45000` milliseconds. The value is unambiguous: **45 seconds** between each heartbeat frame sent to maintain the WebSocket connection.

## How to Override the Default Value

To use a custom heartbeat interval, pass the `heartbeatInterval` property (measured in milliseconds) when instantiating the gateway:

```typescript
import { CloddsGateway } from 'cloddsbot/src/gateway';

// Custom 30-second heartbeat for faster detection
const gateway = new CloddsGateway({
  heartbeatInterval: 30_000,
  // ...other required configuration options
});

gateway.start();

```

If you omit the `heartbeatInterval` property entirely, the constructor automatically inherits the 45-second default defined in the source.

## Distinguishing WebSocket from Other Heartbeat Intervals

The CloddsBot repository contains multiple heartbeat implementations that use different default timings. Do not confuse the WebSocket default with these subsystem-specific values:

- **ACP Component**: [`src/acp/index.ts`](https://github.com/alsk1992/CloddsBot/blob/main/src/acp/index.ts) (line 81) implements a default of `30000` ms (30 seconds) for administrative control plane operations.
- **API Routes**: [`src/gateway/api-routes.ts`](https://github.com/alsk1992/CloddsBot/blob/main/src/gateway/api-routes.ts) (line 852) utilizes `30_000` ms for HTTP-SSE (Server-Sent Events) keepalive mechanisms.

Only the WebSocket gateway in [`src/gateway/index.ts`](https://github.com/alsk1992/CloddsBot/blob/main/src/gateway/index.ts) uses the 45-second default.

## Configuration Examples

Using the default 45-second interval requires no explicit configuration:

```typescript
// Automatically uses 45000ms from src/gateway/index.ts
const defaultGateway = new CloddsGateway({
  // heartbeatInterval intentionally omitted
});

```

For environments requiring more aggressive connection monitoring, override with a shorter interval:

```typescript
const highFrequencyGateway = new CloddsGateway({
  heartbeatInterval: 15_000, // 15 seconds
});

```

## Summary

- The default WebSocket heartbeat interval in CloddsBot is **45 seconds (45,000 ms)**.
- This default is hardcoded in [`src/gateway/index.ts`](https://github.com/alsk1992/CloddsBot/blob/main/src/gateway/index.ts) at line 144 using the nullish coalescing operator (`??`).
- Supply a custom `heartbeatInterval` (in milliseconds) via the gateway configuration object to override the default.
- Other components such as the ACP module and HTTP-SSE routes use a 30-second default, but these operate independently of the WebSocket implementation.

## Frequently Asked Questions

### What is the exact default heartbeat interval for CloddsBot WebSocket connections?

The exact default is **45,000 milliseconds (45 seconds)**. This value is explicitly set as a fallback in [`src/gateway/index.ts`](https://github.com/alsk1992/CloddsBot/blob/main/src/gateway/index.ts) when the `heartbeatInterval` configuration property is `null` or `undefined`.

### How do I configure a custom heartbeat interval in CloddsBot?

Pass the `heartbeatInterval` property as a number representing milliseconds in the configuration object when creating a new `CloddsGateway` instance. For example, set `heartbeatInterval: 30_000` to establish a 30-second interval instead of the default 45 seconds.

### Does CloddsBot use the same heartbeat interval for HTTP-SSE connections?

No. While the WebSocket gateway defaults to 45 seconds, the HTTP-SSE implementation in [`src/gateway/api-routes.ts`](https://github.com/alsk1992/CloddsBot/blob/main/src/gateway/api-routes.ts) (line 852) uses a `30_000` ms (30-second) interval for its keepalive signals. The ACP component in [`src/acp/index.ts`](https://github.com/alsk1992/CloddsBot/blob/main/src/acp/index.ts) also uses a 30-second default, but these intervals are not interchangeable with the WebSocket configuration.

### Will the default apply if I explicitly set heartbeatInterval to null?

Yes. Because the gateway constructor uses the nullish coalescing operator (`config.heartbeatInterval ?? 45000`), any `null` or `undefined` value triggers the fallback to 45,000 ms. Only explicitly defined positive numbers will override this behavior.