The bundled internal/channels/telegram package (17 files) is deleted; the channel now ships as archipelago/channels/telegram, launched by archiemessaging through the existing channel-extension machinery. An existing [chat.telegram] config enables it with the same keys: the token stays a secret reference (token_ref) the host resolves, allowed_user_ids and show_tool_calls map onto extension settings. Per-org bots compose the same extension per org from the org's credential binding. Reload support is now derived from a channels.Reloader interface instead of a *telegram.Gateway assertion. The five host-only seams (/update, release announcements, running versions, in-place show_tool_calls, reload) are dropped from the channel and need a contract home or deletion.
74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
package messaging
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/samcharles93/archie-core/internal/webhookguard"
|
|
)
|
|
|
|
const (
|
|
toolParametersMaxRunes = 120
|
|
redactedParameterValue = "[redacted]"
|
|
)
|
|
|
|
// SummarizeToolParameters returns a bounded JSON shape of tool input.
|
|
func SummarizeToolParameters(input string) string {
|
|
if strings.TrimSpace(input) == "" {
|
|
return ""
|
|
}
|
|
decoder := json.NewDecoder(strings.NewReader(input))
|
|
decoder.UseNumber()
|
|
var value any
|
|
if err := decoder.Decode(&value); err != nil {
|
|
return "[unavailable]"
|
|
}
|
|
value = redactToolParameters(value, false)
|
|
encoded, err := json.Marshal(value)
|
|
if err != nil {
|
|
return "[unavailable]"
|
|
}
|
|
return truncateRunesWithinLimit(string(encoded), toolParametersMaxRunes)
|
|
}
|
|
|
|
func redactToolParameters(value any, sensitive bool) any {
|
|
if sensitive {
|
|
return redactedParameterValue
|
|
}
|
|
switch typed := value.(type) {
|
|
case map[string]any:
|
|
for key, child := range typed {
|
|
typed[key] = redactToolParameters(child, sensitiveParameterKey(key))
|
|
}
|
|
return typed
|
|
case []any:
|
|
for i, child := range typed {
|
|
typed[i] = redactToolParameters(child, sensitive)
|
|
}
|
|
return typed
|
|
default:
|
|
return value
|
|
}
|
|
}
|
|
|
|
func sensitiveParameterKey(key string) bool {
|
|
normalized := strings.NewReplacer("-", "_", " ", "_").Replace(strings.ToLower(key))
|
|
for _, marker := range webhookguard.SensitiveKeyMarkers {
|
|
if strings.Contains(normalized, marker) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func truncateRunesWithinLimit(s string, limit int) string {
|
|
runes := []rune(s)
|
|
if len(runes) <= limit {
|
|
return s
|
|
}
|
|
if limit <= 1 {
|
|
return "…"
|
|
}
|
|
return string(runes[:limit-1]) + "…"
|
|
}
|