44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/theorift/white-zone-bot/bot"
|
|
"gopkg.in/telebot.v4"
|
|
)
|
|
|
|
func HandleGenerateInviteQueryBtn(bot bot.Bot) {
|
|
bot.GetInstance().Handle(telebot.OnQuery, func(ctx telebot.Context) error {
|
|
slog.Debug("OnQuery triggered")
|
|
if ctx.Query().Text != "invite" {
|
|
slog.Debug("The query wasn't an invite query!")
|
|
return nil
|
|
}
|
|
senderID := ctx.Sender().ID
|
|
slog.Debug("Sender identified.", "senderID", senderID)
|
|
|
|
inviteLink := fmt.Sprintf(
|
|
"https://t.me/%s?start=%d",
|
|
bot.GetInstance().Me.Username,
|
|
senderID,
|
|
)
|
|
slog.Debug("Done generating invite link.", "inviteLink", inviteLink)
|
|
|
|
// Create an inline query result.
|
|
article := &telebot.ArticleResult{
|
|
Title: "Join Our VIP Group!",
|
|
Description: "Click to join our exclusive group.",
|
|
Text: fmt.Sprintf("Join our VIP Group using this link: %s", inviteLink),
|
|
URL: inviteLink,
|
|
}
|
|
|
|
return ctx.Answer(
|
|
&telebot.QueryResponse{
|
|
Results: []telebot.Result{article},
|
|
},
|
|
)
|
|
})
|
|
|
|
}
|