telegram-bot-api
telegram-bot-api copied to clipboard
Inline query cache time is not working
I am implementing inline queries using the telegram-bot-api package and followed the basic example from the official documentation. The InlineConfig is set to return a unique random value, but I am experiencing an issue where the response is cached despite having CacheTime set to 0.
Here's the relevant code snippet:
package main
import (
"log"
"math/rand"
"os"
"strconv"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load(".env")
token := os.Getenv("BOT_TOKEN")
bot, err := tgbotapi.NewBotAPI(token)
if err != nil {
log.Panic(err)
}
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
for update := range updates {
if update.InlineQuery == nil {
continue
}
source := rand.NewSource(time.Now().UnixNano())
r := rand.New(source)
randomValue := strconv.Itoa(r.Int()) // this value should be unique for each request
article := tgbotapi.NewInlineQueryResultArticle(update.InlineQuery.ID, "Echo", randomValue)
article.Description = update.InlineQuery.Query
inlineConf := tgbotapi.InlineConfig{
InlineQueryID: update.InlineQuery.ID,
IsPersonal: true,
CacheTime: 0,
Results: []interface{}{article},
}
if _, err := bot.Request(inlineConf); err != nil {
log.Println(err)
}
}
}
Expected Behavior: Each bot response returns unique value Actual Behavior: The same random value is returned on subsequent requests, indicating that the response is cached. Environment: Go 1.22, telegram-bot-api version 5.5.1