Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline query cache time is not working #740

Open
OlegZapara opened this issue Jul 12, 2024 · 0 comments
Open

Inline query cache time is not working #740

OlegZapara opened this issue Jul 12, 2024 · 0 comments

Comments

@OlegZapara
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant