Files
ba621391c2 feat(telegram): trigger-words, channel posts, message edit & topic posting (#1383)
- Fix image_generation nil-pointer crash on codex agents: the sentinel now
  carries a name-only Function so the many sites reading td.Function.Name never
  nil-deref; codex_build still branches on Type.
- Agent-declared trigger words in IDENTITY.md wake the bot in groups without an
  @mention (whole-word, Cyrillic-aware; text + caption), cached per-agent 60s.
- channel_post support with a synthetic sender + a recover() guard so a
  malformed update can't crash the gateway.
- message tool action=edit (editMessageText + editMessageCaption fallback),
  targeting the replied-to message via reply_to_message_id.
- message tool topic=<name> posts into a named forum topic; topics learned from
  forum_topic_created into channel_contacts and resolved by name.

Co-authored-by: skensel <skensel@MacBook-Pro-skensel.local>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 12:28:18 +07:00

43 lines
1.3 KiB
Go

package bootstrap
import "strings"
// ParseTriggerWords extracts the agent's trigger-word aliases from IDENTITY.md.
//
// Trigger words let an agent respond in group chats when named by an alias
// (e.g. "Alice") without an explicit @mention. They are declared in IDENTITY.md
// using the existing Key: Value convention, comma-separated:
//
// Trigger words: Alice, Boss, Chief
//
// The key match is case-insensitive and tolerates the markdown bullet form
// (`- **Trigger words:** …`) and the singular "Trigger word". Returns nil when
// no trigger-word line is present.
func ParseTriggerWords(identityContent string) []string {
for line := range strings.SplitSeq(identityContent, "\n") {
line = strings.TrimSpace(line)
// Strip markdown bullet + bold markers: "- **Trigger words:** x" → "Trigger words:** x".
line = strings.TrimPrefix(line, "-")
line = strings.TrimSpace(line)
line = strings.ReplaceAll(line, "*", "")
idx := strings.Index(line, ":")
if idx <= 0 {
continue
}
key := strings.ToLower(strings.TrimSpace(line[:idx]))
if key != "trigger words" && key != "trigger word" {
continue
}
var words []string
for w := range strings.SplitSeq(line[idx+1:], ",") {
if w = strings.TrimSpace(w); w != "" {
words = append(words, w)
}
}
return words
}
return nil
}