Skip to main content

walrus_channel/
config.rs

1//! Channel configuration types.
2
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6/// Supported channel platforms.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum ChannelType {
10    /// Telegram bot via long-polling.
11    Telegram,
12    /// Discord bot via WebSocket gateway.
13    Discord,
14}
15
16impl ChannelType {
17    /// All known variants, in definition order.
18    pub const VARIANTS: &[Self] = &[Self::Telegram, Self::Discord];
19
20    /// URL hint for obtaining a bot token for this platform.
21    pub fn token_hint(self) -> &'static str {
22        match self {
23            Self::Telegram => "https://core.telegram.org/bots#botfather",
24            Self::Discord => "https://discord.com/developers/applications",
25        }
26    }
27}
28
29impl fmt::Display for ChannelType {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            Self::Telegram => f.write_str("Telegram"),
33            Self::Discord => f.write_str("Discord"),
34        }
35    }
36}
37
38/// Telegram bot configuration.
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct TelegramConfig {
41    /// Bot token from @BotFather.
42    pub token: String,
43}
44
45/// Discord bot configuration.
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct DiscordConfig {
48    /// Bot token from the Discord developer portal.
49    pub token: String,
50}
51
52/// Top-level channel configuration.
53///
54/// Deserialized from `[channel.telegram]` / `[channel.discord]` TOML tables.
55#[derive(Debug, Clone, Serialize, Deserialize, Default)]
56pub struct ChannelConfig {
57    /// Telegram bot config. Absent means no Telegram bot.
58    pub telegram: Option<TelegramConfig>,
59    /// Discord bot config. Absent means no Discord bot.
60    pub discord: Option<DiscordConfig>,
61}