Skip to content

Instantly share code, notes, and snippets.

@jezman
Created March 14, 2017 10:48
Show Gist options
  • Save jezman/241613bcf6daeab29bc3236b2b6ca27a to your computer and use it in GitHub Desktop.
Save jezman/241613bcf6daeab29bc3236b2b6ca27a to your computer and use it in GitHub Desktop.
Send message to telegram chat.
package main
import (
"fmt"
"net/http"
"os"
"strings"
)
const (
botID = "yourbotID"
chatID = "chat_id"
host = "https://api.telegram.org/bot"
)
func main() {
url := host + botID + "/sendMessage"
message := os.Args[2:]
req, _ := http.NewRequest("GET", url, nil)
query := req.URL.Query()
query.Add("chat_id", chatID)
query.Add("text", strings.Join(message, " "))
req.URL.RawQuery = query.Encode()
resp, err := http.Get(req.URL.String())
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment