MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / extractTelegramConfig

Function extractTelegramConfig

agent/app/service/agents_channels.go:787–849  ·  view source on GitHub ↗
(conf map[string]interface{})

Source from the content-addressed store, hash-verified

785}
786
787func 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 }

Callers 2

GetTelegramConfigMethod · 0.85

Calls 10

getChannelConfigFunction · 0.85
extractStringValueFunction · 0.85
extractStringListFunction · 0.85
childMapFunction · 0.85
extractBoolValueFunction · 0.85
sortedChildKeysFunction · 0.85
extractDisplayNameFunction · 0.85
normalizeDefaultAccountFunction · 0.85
getTelegramBotAccountIDsFunction · 0.85
setTelegramDefaultFlagsFunction · 0.85

Tested by

no test coverage detected