first commit

This commit is contained in:
tgvpn
2026-05-21 00:25:44 +03:00
commit 626128673d
6 changed files with 97 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
package main
import (
"log"
"os"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/joho/godotenv"
)
func main() {
_ = godotenv.Load()
token := os.Getenv("BOT_TOKEN")
if token == "" {
log.Fatal("BOT_TOKEN не задан. Скопируйте .env.example в .env и укажите токен от @BotFather")
}
bot, err := tgbotapi.NewBotAPI(token)
if err != nil {
log.Fatalf("не удалось подключиться к Telegram: %v", err)
}
bot.Debug = os.Getenv("BOT_DEBUG") == "true"
log.Printf("бот @%s запущен", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil {
continue
}
chatID := update.Message.Chat.ID
text := update.Message.Text
var reply string
switch text {
case "/start":
name := update.Message.From.FirstName
if name == "" {
name = "друг"
}
reply = "Привет, " + name + "!\n\nЯ VPN-бот. Пока умею только здороваться — дальше добавим функции."
default:
reply = "Напишите /start, чтобы начать."
}
msg := tgbotapi.NewMessage(chatID, reply)
if _, err := bot.Send(msg); err != nil {
log.Printf("ошибка отправки в чат %d: %v", chatID, err)
}
}
}