package main
import (
"fmt"
"github.com/amarnathcjd/gogram/telegram"
)
func main() {
// Create and authenticate the client
client, _ := telegram.NewClient(telegram.ClientConfig{
AppID: 6,
AppHash: "YOUR_APP_HASH",
})
// Login as user (required to access chat history)
client.Login("+1234567890")
// Get last 5 messages from a chat
// Can use username (@username), chat ID, or "me" for saved messages
messages, _ := client.GetHistory("@username", &telegram.HistoryOption{
Limit: 5, // Number of messages to retrieve
})
// Alternative: client.IterHistory() for yielding messages one by one
// Useful for large histories to avoid memory issues
// Print each message's text
for _, message := range messages {
fmt.Println(message.Text())
}
client.Idle()
}