How do I call Telegram Bot API in Go?

This example demonstrates how to interact with the Telegram Bot API using Go programming language. It provides a simple method to send messages to users through a Telegram bot.
Telegram Bot API, Go programming, Bot communication, Send messages, Go Telegram bot
package main import ( "bytes" "encoding/json" "net/http" "os" ) const apiUrl = "https://api.telegram.org/bot%s/sendMessage" func main() { botToken := os.Getenv("TELEGRAM_BOT_TOKEN") chatID := "your_chat_id" message := "Hello, this is a message from your Go bot!" sendMessage(botToken, chatID, message) } func sendMessage(botToken, chatID, message string) { url := fmt.Sprintf(apiUrl, botToken) payload := map[string]interface{}{ "chat_id": chatID, "text": message, } payloadBytes, _ := json.Marshal(payload) _, err := http.Post(url, "application/json", bytes.NewBuffer(payloadBytes)) if err != nil { log.Fatalf("Error sending message: %v", err) } }

Telegram Bot API Go programming Bot communication Send messages Go Telegram bot