Skip to content

Commit

Permalink
debug and last try
Browse files Browse the repository at this point in the history
  • Loading branch information
AshokShau committed Oct 18, 2024
1 parent 18619fa commit 8a0710e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Telegram/modules/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ type Field struct {

// isVercel checks if the application is running on Vercel.
func isVercel() bool {
log.Println(config.VERCEL)
return config.VERCEL == "1"
}

// fetchAPI fetches the API documentation from a remote source and updates the apiCache.
func fetchAPI() error {
log.Println("Starting API fetch")
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Get(apiURL)
if err != nil {
Expand All @@ -74,6 +76,8 @@ func fetchAPI() error {
return fmt.Errorf("failed to decode API response: %w", err)
}

log.Println("Fetched API documentation:", apiDocs) // Log the fetched data

apiCache.Lock()
defer apiCache.Unlock()
apiCache.Methods = apiDocs.Methods
Expand Down Expand Up @@ -113,8 +117,9 @@ func getAPICache() (map[string]Method, map[string]Type, error) {
// inlineQueryHandler handles inline queries from the bot.
func inlineQueryHandler(bot *gotgbot.Bot, ctx *ext.Context) error {
query := strings.TrimSpace(ctx.InlineQuery.Query)
parts := strings.Fields(query)
log.Println("Received inline query:", query)

parts := strings.Fields(query)
if len(parts) == 0 {
return sendEmptyQueryResponse(bot, ctx)
}
Expand All @@ -126,9 +131,12 @@ func inlineQueryHandler(bot *gotgbot.Bot, ctx *ext.Context) error {

methods, types, err := getAPICache()
if err != nil {
return fmt.Errorf("failed to get API cache: %w", err)
log.Println("Error getting API cache:", err)
return sendNoResultsResponse(bot, ctx, query)
}

results := searchAPI(query, methods, types)
log.Println("Search results for query:", results)

if len(results) == 0 {
return sendNoResultsResponse(bot, ctx, query)
Expand Down

0 comments on commit 8a0710e

Please sign in to comment.