package mainimport ( "fmt" "github.com/amarnathcjd/gogram/telegram")func main() { client, _ := telegram.NewClient(telegram.ClientConfig{ AppID: 6, AppHash: "YOUR_APP_HASH", }) // Login as user account (required for inline queries) client.Login("+1234567890") // Perform an inline query to another bot results, err := client.InlineQuery("@botusername", &telegram.InlineOptions{ Dialog: "@wheretoperform", // Chat where bot will be invoked Query: "the query", // Search query to send to bot }) if err != nil { fmt.Println("Error:", err) return } // Display results fmt.Printf("Got %d results from inline bot\n", len(results)) for i, result := range results { fmt.Printf("%d. %s\n", i+1, result.Title) } // Send first result to a chat if len(results) > 0 { client.SendInlineResult("@wheretoperform", results[0]) } client.Idle()}
// Use @pic bot to search for imagesfunc SearchImages(client *telegram.Client, query string) { results, err := client.InlineQuery("@pic", &telegram.InlineOptions{ Dialog: "me", // Use "me" for Saved Messages Query: query, }) if err != nil { fmt.Println("Error:", err) return } fmt.Printf("Found %d images for '%s'\n", len(results), query) // Send first image to Saved Messages if len(results) > 0 { client.SendInlineResult("me", results[0]) }}
Search GIFs
Copy
// Use @gif bot to search for GIFsfunc SearchGIFs(client *telegram.Client, query string) { results, err := client.InlineQuery("@gif", &telegram.InlineOptions{ Dialog: "me", Query: query, }) if err != nil { fmt.Println("Error:", err) return } // Send all results to a channel for _, result := range results { client.SendInlineResult("@mychannel", result) time.Sleep(1 * time.Second) // Rate limiting }}
YouTube Search
Copy
// Use @youtube bot to search videosfunc SearchYouTube(client *telegram.Client, query string, chat string) { results, err := client.InlineQuery("@youtube", &telegram.InlineOptions{ Dialog: chat, Query: query, }) if err != nil { fmt.Println("Error:", err) return } fmt.Println("YouTube results:") for i, result := range results { fmt.Printf("%d. %s\n", i+1, result.Title) } // Let user choose which result to send // (In a real bot, you'd use keyboards for selection)}
Location Search
Copy
// Use location-based inline botfunc SearchNearby(client *telegram.Client, lat, long float64) { results, err := client.InlineQuery("@foursquare", &telegram.InlineOptions{ Dialog: "me", Query: "restaurants", GeoPoint: &telegram.InputGeoPoint{ Lat: lat, Long: long, }, }) if err != nil { fmt.Println("Error:", err) return } fmt.Printf("Found %d nearby places\n", len(results))}
Pagination Example
Copy
// Get more results using paginationfunc GetAllResults(client *telegram.Client, botUsername, query string) { offset := "" allResults := []telegram.InlineResult{} for { results, err := client.InlineQuery(botUsername, &telegram.InlineOptions{ Dialog: "me", Query: query, Offset: offset, }) if err != nil || len(results) == 0 { break } allResults = append(allResults, results...) // Get next offset (implementation depends on bot) // Some bots include offset in response offset = getNextOffset(results) if offset == "" { break } } fmt.Printf("Total results: %d\n", len(allResults))}