forked from TeamKillerX/RyuzakiLib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtelegram.go
53 lines (48 loc) · 1.24 KB
/
telegram.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
const (
BOT_ID = "your_bot_id"
TOKEN = "your_token"
)
func botTokenAccess(botID, token string) string {
url := fmt.Sprintf("https://api.telegram.org/bot%s%s/sendMessage", botID, token)
return url
}
func sendMessage(userID, text string) string {
urls := botTokenAccess(BOT_ID, TOKEN)
payload := fmt.Sprintf(`{"chat_id": "%s", "text": "%s", "disable_web_page_preview": true, "disable_notification": false, "reply_to_message_id": null}`, userID, text)
response := ""
client := &http.Client{}
req, err := http.NewRequest("POST", urls, strings.NewReader(payload))
if err != nil {
fmt.Println(err)
return response
}
req.Header.Add("accept", "application/json")
req.Header.Add("User-Agent", "Telegram Bot SDK - (https://github.com/irazasyed/telegram-bot-sdk)")
req.Header.Add("content-type", "application/json")
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return response
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return response
}
response = string(body)
return response
}
func main() {
userID := "your_user_id"
text := "Hello, World!"
result := sendMessage(userID, text)
fmt.Println(result)
}