Created
March 14, 2017 10:48
-
-
Save jezman/241613bcf6daeab29bc3236b2b6ca27a to your computer and use it in GitHub Desktop.
Send message to telegram chat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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