- Telegram integration for customer statistics - MCP server implementation with rate limiting - Cache system for performance optimization - Multi-language support - RESTful API endpoints 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package telegram
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"unicode"
|
|
|
|
"github.com/gotd/td/tg"
|
|
)
|
|
|
|
func findCallbackButton(message *tg.Message, keyword string) (*tg.KeyboardButtonCallback, error) {
|
|
markup, ok := message.ReplyMarkup.(*tg.ReplyInlineMarkup)
|
|
if !ok || len(markup.Rows) == 0 {
|
|
return nil, fmt.Errorf("message has no interactive buttons")
|
|
}
|
|
|
|
normalizedKeyword := strings.ToLower(normalizeButtonText(keyword))
|
|
available := make([]string, 0)
|
|
|
|
for _, row := range markup.Rows {
|
|
for _, button := range row.Buttons {
|
|
callback, ok := button.(*tg.KeyboardButtonCallback)
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
text := callback.Text
|
|
normalized := strings.ToLower(normalizeButtonText(text))
|
|
available = append(available, normalizeButtonText(text))
|
|
|
|
if strings.Contains(normalized, normalizedKeyword) {
|
|
return callback, nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, fmt.Errorf("button containing '%s' not found (available: %s)", keyword, strings.Join(available, ", "))
|
|
}
|
|
|
|
func extractTotalPages(message *tg.Message) int {
|
|
markup, ok := message.ReplyMarkup.(*tg.ReplyInlineMarkup)
|
|
if !ok {
|
|
return 0
|
|
}
|
|
|
|
for _, row := range markup.Rows {
|
|
for _, button := range row.Buttons {
|
|
callback, ok := button.(*tg.KeyboardButtonCallback)
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
if strings.Contains(callback.Text, "⏭") {
|
|
digits := strings.Builder{}
|
|
for _, r := range normalizeButtonText(callback.Text) {
|
|
if unicode.IsDigit(r) {
|
|
digits.WriteRune(r)
|
|
}
|
|
}
|
|
if digits.Len() > 0 {
|
|
if value, err := strconv.Atoi(digits.String()); err == nil {
|
|
return value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0
|
|
}
|