telegram-bot-api icon indicating copy to clipboard operation
telegram-bot-api copied to clipboard

Inline query cache time is not working

Open OlegZapara opened this issue 1 year ago • 0 comments

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

OlegZapara avatar Jul 12 '24 21:07 OlegZapara