client: make ping interval and timeout configurable
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gotd/td/telegram"
|
||||
"github.com/gotd/td/telegram/updates"
|
||||
@@ -177,6 +178,8 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
|
||||
OnSession: func() {
|
||||
login.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
|
||||
},
|
||||
PingTimeout: time.Duration(tc.Config.Ping.TimeoutSeconds) * time.Second,
|
||||
PingInterval: time.Duration(tc.Config.Ping.IntervalSeconds) * time.Second,
|
||||
})
|
||||
client.clientCancel, err = connectTelegramClient(ctx, client.client)
|
||||
|
||||
|
||||
@@ -37,6 +37,11 @@ type TelegramConfig struct {
|
||||
MemberList MemberListConfig `yaml:"member_list"`
|
||||
|
||||
MaxMemberCount int `yaml:"max_member_count"`
|
||||
|
||||
Ping struct {
|
||||
IntervalSeconds int `yaml:"interval_seconds"`
|
||||
TimeoutSeconds int `yaml:"timeout_seconds"`
|
||||
} `yaml:"ping"`
|
||||
}
|
||||
|
||||
func (c TelegramConfig) ShouldBridge(participantCount int) bool {
|
||||
@@ -58,6 +63,8 @@ func upgradeConfig(helper up.Helper) {
|
||||
helper.Copy(up.Bool, "member_list", "sync_broadcast_channels")
|
||||
helper.Copy(up.Bool, "member_list", "skip_deleted")
|
||||
helper.Copy(up.Int, "max_member_count")
|
||||
helper.Copy(up.Int, "ping", "interval_seconds")
|
||||
helper.Copy(up.Int, "ping", "timeout_seconds")
|
||||
}
|
||||
|
||||
func (tg *TelegramConnector) GetConfig() (example string, data any, upgrader up.Upgrader) {
|
||||
|
||||
@@ -47,3 +47,10 @@ member_list:
|
||||
#
|
||||
# -1 means no limit (which means all chats can be bridged)
|
||||
max_member_count: -1
|
||||
|
||||
# Settings for pings to the Telegram server.
|
||||
ping:
|
||||
# The interval (in seconds) between pings.
|
||||
interval_seconds: 30
|
||||
# The timeout (in seconds) for a single ping.
|
||||
timeout_seconds: 10
|
||||
|
||||
Reference in New Issue
Block a user