# How to Monitor bilistream Live Broadcast Status with Gotify: Complete Configuration Guide

> Easily monitor bilistream live broadcast status with Gotify. Configure notifications in configyaml and receive alerts when monitored channels go live.

- Repository: [InitCool/bilistream](https://github.com/limitcool/bilistream)
- Tags: how-to-guide
- Published: 2026-03-06

---

**Configure a Gotify endpoint in [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml) and bilistream will automatically push notifications to your Gotify server whenever a monitored YouTube or Twitch channel begins broadcasting.**

The **bilistream** application from the `limitcool/bilistream` repository continuously monitors live streaming platforms and can alert you via **Gotify** the moment a stream goes online. By implementing the `Live` trait for platform-specific adapters and integrating with the Gotify push API, bilistream bridges live status detection with instant mobile notifications. This guide explains the exact configuration and code paths required to enable live broadcast monitoring with Gotify notifications.

## How bilistream Detects Live Broadcast Status

The core monitoring mechanism relies on the **`Live`** trait defined in [`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs). This trait abstracts live-status checking across multiple platforms:

```rust
#[async_trait]
pub trait Live {
    async fn get_status(&self) -> Result<bool, Box<dyn Error>>;
    fn room(&self) -> &str;
    async fn get_real_m3u8_url(&self) -> Result<String, Box<dyn Error>>;
    fn set_room(&mut self, room: &str);
}

```

Platform implementations (e.g., `Youtube`, `Twitch`) provide concrete logic for `get_status`, which returns `true` when a broadcast is active. The `select_live` factory function instantiates the appropriate adapter based on your configuration, allowing bilistream to poll `r.get_status().await` uniformly regardless of the underlying platform.

## Configuring Gotify in bilistream

To receive push notifications, you must define a **Gotify** section in your [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml). The `Config` struct in [`src/config.rs`](https://github.com/limitcool/bilistream/blob/main/src/config.rs) declares this as an optional field:

```rust
pub struct Config {
    pub gotify: Option<GotifyConfig>,
    // ... other fields
}

```

Add the following to your configuration file:

```yaml
Gotify:
  Url: "https://your-gotify-server.com/message"
  Token: "YOUR_GOTIFY_APP_TOKEN"

```

The **`GotifyConfig`** struct expects a `url` string pointing to your Gotify message endpoint and a `token` string containing your application token. When this configuration is present, bilistream initializes the notification pipeline; when absent, the application skips Gotify alerts and continues with stream recording only.

## The Notification Workflow: From Status Check to Alert

The main event loop in [`src/main.rs`](https://github.com/limitcool/bilistream/blob/main/src/main.rs) orchestrates the monitoring and notification sequence. Every polling cycle executes the following logic:

1. **Status Check**: Calls `r.get_status().await.unwrap_or(false)` on the live platform adapter
2. **Online Detection**: When the result is `true`, the stream is marked as live
3. **Notification Trigger**: If `cfg.gotify` is `Some`, bilistream invokes `send_gotify_notification`

```rust
if r.get_status().await.unwrap_or(false) {
    tracing::info!("{}直播中", r.room());

    if let Some(ref gotify_config) = cfg.gotify {
        send_gotify_notification(
            &gotify_config,
            &format!("{}开始直播", r.room()),
            "bilistream",
        )
        .await;
    }
    // ... ffmpeg and Bilibili upload logic follows
}

```

This implementation ensures notifications fire immediately upon broadcast detection, using the `tracing` crate to log successful dispatches or connection errors.

## Gotify Client Implementation Details

The actual HTTP push logic resides in [`src/push.rs`](https://github.com/limitcool/bilistream/blob/main/src/push.rs) within the **`send_gotify_notification`** function:

```rust
pub async fn send_gotify_notification(
    config: &GotifyConfig,
    message: &str,
    title: &str,
) {
    match GotifyClient::new(config.url.as_str(), &config.token) {
        Ok(client) => match client.create_message(message).with_title(title).await {
            Ok(_) => tracing::info!("Gotify通知发送成功"),
            Err(e) => tracing::error!("Gotify通知发送失败: {}", e),
        },
        Err(e) => tracing::error!("Gotify客户端创建失败: {}", e),
    }
}

```

The function constructs a `GotifyClient` using your configured URL and token, then dispatches a message with the provided title. Error handling covers both client instantiation failures (invalid URL/token) and message transmission failures, ensuring bilistream remains stable even if your Gotify server is temporarily unreachable.

## Summary

- **Configuration**: Add the `Gotify` block to [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml) with `Url` and `Token` fields as defined in [`src/config.rs`](https://github.com/limitcool/bilistream/blob/main/src/config.rs)
- **Monitoring**: The `Live` trait in [`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs) standardizes status checking across YouTube, Twitch, and other platforms via `get_status()`
- **Triggering**: The main loop in [`src/main.rs`](https://github.com/limitcool/bilistream/blob/main/src/main.rs) evaluates `r.get_status().await` and calls `send_gotify_notification()` only when the stream transitions to online
- **Delivery**: [`src/push.rs`](https://github.com/limitcool/bilistream/blob/main/src/push.rs) handles the Gotify HTTP API integration, formatting messages with the channel name and "bilistream" title

## Frequently Asked Questions

### What is the minimum configuration required to enable Gotify notifications in bilistream?

You must add a `Gotify` section to your [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml) containing two fields: `Url` (your Gotify server message endpoint) and `Token` (your Gotify application token). The `Config` struct in [`src/config.rs`](https://github.com/limitcool/bilistream/blob/main/src/config.rs) parses these into a `GotifyConfig` instance; bilistream checks `cfg.gotify.is_some()` before attempting any push notifications.

### Which live streaming platforms does bilistream support for Gotify alerts?

bilistream supports any platform implementing the `Live` trait in [`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs), including YouTube and Twitch. The `select_live` factory creates platform-specific instances (e.g., `Youtube`, `Twitch`) that each implement `get_status()`, allowing the same Gotify notification logic to work uniformly across different streaming services.

### How does bilistream handle Gotify server errors or connectivity issues?

The `send_gotify_notification` function in [`src/push.rs`](https://github.com/limitcool/bilistream/blob/main/src/push.rs) uses `match` expressions to catch and log errors via the `tracing` crate. If the Gotify client fails to initialize or the message fails to send, bilistream logs the error with `tracing::error!()` but continues executing the main loop, ensuring that temporary notification failures do not interrupt the live stream recording process.

### Can I customize the notification title and message format sent to Gotify?

Yes. The main loop in [`src/main.rs`](https://github.com/limitcool/bilistream/blob/main/src/main.rs) calls `send_gotify_notification` with a formatted message string: `format!("{}开始直播", r.room())`. You can modify this format string in the source code to include additional metadata such as the platform name or current timestamp. The title parameter ("bilistream" by default) can also be changed in the same function call.