(conf map[string]interface{})
| 785 | } |
| 786 | |
| 787 | func extractTelegramConfig(conf map[string]interface{}) dto.AgentTelegramConfig { |
| 788 | result := dto.AgentTelegramConfig{ |
| 789 | Enabled: true, |
| 790 | DmPolicy: "pairing", |
| 791 | AllowFrom: []string{}, |
| 792 | RequireMention: false, |
| 793 | GroupPolicy: "open", |
| 794 | GroupAllowFrom: []string{}, |
| 795 | Streaming: "partial", |
| 796 | } |
| 797 | telegram := getChannelConfig(conf, "telegram") |
| 798 | if len(telegram) == 0 { |
| 799 | return result |
| 800 | } |
| 801 | if enabled, ok := telegram["enabled"].(bool); ok { |
| 802 | result.Enabled = enabled |
| 803 | } |
| 804 | if dmPolicy := extractStringValue(telegram["dmPolicy"]); dmPolicy != "" { |
| 805 | result.DmPolicy = dmPolicy |
| 806 | } |
| 807 | result.AllowFrom = extractStringList(telegram["allowFrom"]) |
| 808 | if groupPolicy := extractStringValue(telegram["groupPolicy"]); groupPolicy != "" { |
| 809 | result.GroupPolicy = groupPolicy |
| 810 | } |
| 811 | result.RequireMention = result.GroupPolicy == "allowlist" |
| 812 | result.GroupAllowFrom = extractStringList(telegram["groupAllowFrom"]) |
| 813 | result.Proxy = extractStringValue(telegram["proxy"]) |
| 814 | if streaming := extractStringValue(telegram["streaming"]); streaming != "" { |
| 815 | result.Streaming = streaming |
| 816 | } |
| 817 | accounts := childMap(telegram, "accounts") |
| 818 | if len(accounts) == 0 { |
| 819 | botToken := extractStringValue(telegram["botToken"]) |
| 820 | if botToken != "" { |
| 821 | accounts["default"] = map[string]interface{}{ |
| 822 | "enabled": extractBoolValue(telegram["enabled"], true), |
| 823 | "botToken": botToken, |
| 824 | "dmPolicy": result.DmPolicy, |
| 825 | "groupPolicy": result.GroupPolicy, |
| 826 | "streaming": result.Streaming, |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | bots := make([]dto.AgentTelegramBot, 0, len(accounts)) |
| 831 | for _, accountID := range sortedChildKeys(accounts) { |
| 832 | account := childMap(accounts, accountID) |
| 833 | bots = append(bots, dto.AgentTelegramBot{ |
| 834 | AgentChannelBotBase: dto.AgentChannelBotBase{ |
| 835 | AccountID: accountID, |
| 836 | Name: extractDisplayName(account, accountID, accountID), |
| 837 | Enabled: extractBoolValue(account["enabled"], true), |
| 838 | }, |
| 839 | BotToken: extractStringValue(account["botToken"]), |
| 840 | DmPolicy: extractStringValue(account["dmPolicy"]), |
| 841 | GroupPolicy: extractStringValue(account["groupPolicy"]), |
| 842 | Streaming: extractStringValue(account["streaming"]), |
| 843 | }) |
| 844 | } |
no test coverage detected