Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/config/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@ impl Config {
enabled: instance.enabled && token.is_some(),
token: token.unwrap_or_default(),
dm_allowed_users: instance.dm_allowed_users,
native_streaming: instance.native_streaming,
}
})
.collect::<Vec<_>>();
Expand All @@ -1891,6 +1892,7 @@ impl Config {
token: token.unwrap_or_default(),
instances,
dm_allowed_users: t.dm_allowed_users,
native_streaming: t.native_streaming,
})
}),
email: toml.messaging.email.and_then(|email| {
Expand Down
25 changes: 11 additions & 14 deletions src/config/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ pub struct DiscordPermissions {

impl DiscordPermissions {
/// Build from the current config's discord settings and bindings.
pub fn from_config(discord: &DiscordConfig, bindings: &[Binding]) -> Self {
Self::from_bindings_for_adapter(
discord.dm_allowed_users.clone(),
discord.allow_bot_messages,
bindings,
None,
)
}

/// Build permissions for a named Discord adapter instance.
pub fn from_instance_config(instance: &DiscordInstanceConfig, bindings: &[Binding]) -> Self {
Expand Down Expand Up @@ -121,9 +113,7 @@ pub struct SlackPermissions {

impl SlackPermissions {
/// Build from the current config's slack settings and bindings.
pub fn from_config(slack: &SlackConfig, bindings: &[Binding]) -> Self {
Self::from_bindings_for_adapter(slack.dm_allowed_users.clone(), bindings, None)
}

/// Build permissions for a named Slack adapter instance.
pub fn from_instance_config(instance: &SlackInstanceConfig, bindings: &[Binding]) -> Self {
Expand Down Expand Up @@ -201,25 +191,34 @@ pub struct TelegramPermissions {
pub chat_filter: Option<Vec<i64>>,
/// User IDs allowed in private chats.
pub dm_allowed_users: Vec<i64>,
/// Whether to use native streaming via sendMessageDraft API
pub native_streaming: bool,
}

impl TelegramPermissions {
/// Build from the current config's telegram settings and bindings.
pub fn from_config(telegram: &TelegramConfig, bindings: &[Binding]) -> Self {
Self::from_bindings_for_adapter(telegram.dm_allowed_users.clone(), bindings, None)
Self::from_bindings_for_adapter(
telegram.dm_allowed_users.clone(),
telegram.native_streaming,
bindings,
None,
)
}

/// Build permissions for a named Telegram adapter instance.
pub fn from_instance_config(instance: &TelegramInstanceConfig, bindings: &[Binding]) -> Self {
Self::from_bindings_for_adapter(
instance.dm_allowed_users.clone(),
instance.native_streaming,
bindings,
Some(instance.name.as_str()),
)
}

fn from_bindings_for_adapter(
seed_dm_allowed_users: Vec<String>,
native_streaming: bool,
bindings: &[Binding],
adapter_selector: Option<&str>,
) -> Self {
Expand Down Expand Up @@ -261,6 +260,7 @@ impl TelegramPermissions {
Self {
chat_filter,
dm_allowed_users,
native_streaming,
}
}
}
Expand All @@ -278,9 +278,6 @@ pub struct TwitchPermissions {

impl TwitchPermissions {
/// Build from the current config's twitch settings and bindings.
pub fn from_config(_twitch: &TwitchConfig, bindings: &[Binding]) -> Self {
Self::from_bindings_for_adapter(bindings, None)
}

/// Build permissions for a named Twitch adapter instance.
pub fn from_instance_config(instance: &TwitchInstanceConfig, bindings: &[Binding]) -> Self {
Expand Down
8 changes: 8 additions & 0 deletions src/config/toml_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ pub(super) struct TomlTelegramConfig {
pub(super) instances: Vec<TomlTelegramInstanceConfig>,
#[serde(default)]
pub(super) dm_allowed_users: Vec<String>,
#[serde(default = "default_native_streaming")]
pub(super) native_streaming: bool,
}

#[derive(Deserialize)]
Expand All @@ -571,6 +573,8 @@ pub(super) struct TomlTelegramInstanceConfig {
pub(super) token: Option<String>,
#[serde(default)]
pub(super) dm_allowed_users: Vec<String>,
#[serde(default = "default_native_streaming")]
pub(super) native_streaming: bool,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -721,6 +725,10 @@ pub(super) fn default_email_max_attachment_bytes() -> usize {
10 * 1024 * 1024
}

pub(super) fn default_native_streaming() -> bool {
true
}

#[derive(Deserialize)]
pub(super) struct TomlBinding {
pub(super) agent_id: String,
Expand Down
7 changes: 7 additions & 0 deletions src/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,9 @@ impl SystemSecrets for SlackConfig {

#[derive(Clone)]
pub struct TelegramConfig {
/// Whether to use native streaming via sendMessageDraft API (Bot API 9.5+)
/// Only works for private chats. Defaults to true.
pub native_streaming: bool,
pub enabled: bool,
pub token: String,
/// Additional named Telegram bot instances for this platform.
Expand All @@ -2072,6 +2075,8 @@ pub struct TelegramInstanceConfig {
pub token: String,
/// User IDs allowed to DM this bot instance.
pub dm_allowed_users: Vec<String>,
/// Whether to use native streaming via sendMessageDraft API
pub native_streaming: bool,
}

impl std::fmt::Debug for TelegramInstanceConfig {
Expand All @@ -2081,6 +2086,7 @@ impl std::fmt::Debug for TelegramInstanceConfig {
.field("enabled", &self.enabled)
.field("token", &"[REDACTED]")
.field("dm_allowed_users", &self.dm_allowed_users)
.field("native_streaming", &self.native_streaming)
.finish()
}
}
Expand All @@ -2092,6 +2098,7 @@ impl std::fmt::Debug for TelegramConfig {
.field("token", &"[REDACTED]")
.field("instances", &self.instances)
.field("dm_allowed_users", &self.dm_allowed_users)
.field("native_streaming", &self.native_streaming)
.finish()
}
}
Expand Down
Loading