(conf map[string]interface{}, config dto.AgentTelegramConfig)
| 849 | } |
| 850 | |
| 851 | func setTelegramConfig(conf map[string]interface{}, config dto.AgentTelegramConfig) { |
| 852 | channels := ensureChildMap(conf, "channels") |
| 853 | telegram := ensureChildMap(channels, "telegram") |
| 854 | defaultAccount := normalizeDefaultAccount(config.DefaultAccount, getTelegramBotAccountIDs(config.Bots)) |
| 855 | effectiveEnabled := config.Enabled && hasEnabledBots(config.Bots) |
| 856 | telegram["enabled"] = effectiveEnabled |
| 857 | telegram["dmPolicy"] = config.DmPolicy |
| 858 | telegram["groupPolicy"] = config.GroupPolicy |
| 859 | telegram["defaultAccount"] = defaultAccount |
| 860 | if config.RequireMention { |
| 861 | telegram["groupPolicy"] = "allowlist" |
| 862 | } else if config.GroupPolicy == "allowlist" { |
| 863 | telegram["groupPolicy"] = "allowlist" |
| 864 | } |
| 865 | if config.DmPolicy == "open" { |
| 866 | telegram["allowFrom"] = []string{"*"} |
| 867 | } else if config.DmPolicy == "allowlist" { |
| 868 | telegram["allowFrom"] = append([]string(nil), config.AllowFrom...) |
| 869 | } else { |
| 870 | delete(telegram, "allowFrom") |
| 871 | } |
| 872 | if config.GroupPolicy == "allowlist" { |
| 873 | telegram["groupAllowFrom"] = append([]string(nil), config.GroupAllowFrom...) |
| 874 | } else { |
| 875 | delete(telegram, "groupAllowFrom") |
| 876 | } |
| 877 | if config.Proxy != "" { |
| 878 | telegram["proxy"] = config.Proxy |
| 879 | } else { |
| 880 | delete(telegram, "proxy") |
| 881 | } |
| 882 | telegram["streaming"] = config.Streaming |
| 883 | accounts := make(map[string]interface{}, len(config.Bots)) |
| 884 | for _, bot := range config.Bots { |
| 885 | account := map[string]interface{}{ |
| 886 | "enabled": bot.Enabled, |
| 887 | "name": bot.Name, |
| 888 | "botToken": bot.BotToken, |
| 889 | "dmPolicy": bot.DmPolicy, |
| 890 | "groupPolicy": bot.GroupPolicy, |
| 891 | "streaming": bot.Streaming, |
| 892 | } |
| 893 | if bot.DmPolicy == "open" { |
| 894 | account["allowFrom"] = []string{"*"} |
| 895 | } |
| 896 | accounts[bot.AccountID] = account |
| 897 | } |
| 898 | telegram["accounts"] = accounts |
| 899 | delete(telegram, "botToken") |
| 900 | } |
| 901 | |
| 902 | func extractDiscordConfig(conf map[string]interface{}) dto.AgentDiscordConfig { |
| 903 | result := dto.AgentDiscordConfig{Enabled: true, DmPolicy: "pairing", AllowFrom: []string{}, RequireMention: false, GroupPolicy: "open"} |
no test coverage detected