ruspet_portal_back/service/telegram_service/keyboard/file_input.go

53 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package keyboard
import (
"bitrix_balancer_api/core/utilscore"
"bitrix_balancer_api/telegram_service/state"
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
// BuildFileInputKeyboard строит клавиатуру с кнопками открепления каждого файла,
// кнопкой отправки (с количеством) и кнопкой отправки без файлов.
// keyboard/file_input.go
func BuildFileInputKeyboard(topicCode string, files []state.FileAttachment) tgbotapi.InlineKeyboardMarkup {
var rows [][]tgbotapi.InlineKeyboardButton
// Кнопка «Открепить» для каждого файла
for i, f := range files {
label := []rune(f.FileName)
if len(label) > 25 {
label = append(label[:22], []rune("...")...)
}
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData(
"🗑 "+string(label),
fmt.Sprintf("appr_file_detach:%d", i),
),
))
}
// Кнопка отправки — показывает количество файлов
submitLabel := "✅ Отправить на согласование"
if n := len(files); n > 0 {
submitLabel = fmt.Sprintf("✅ Отправить (%s)", utilscore.PluralFiles(n))
}
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData(submitLabel, "appr_file_submit:"+topicCode),
))
// Кнопка «без файлов» появляется только если уже что-то прикреплено
if len(files) > 0 {
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("📤 Отправить без файлов", "appr_file_skip:"+topicCode),
))
}
// Кнопка «Назад» — всегда внизу
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("← Назад", "appr_back:"+topicCode),
))
return tgbotapi.NewInlineKeyboardMarkup(rows...)
}