-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
main.go
83 lines (63 loc) · 1.79 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"os"
"github.com/mymmrac/telego"
tu "github.com/mymmrac/telego/telegoutil"
)
func main() {
botToken := os.Getenv("TOKEN")
// Note: Please keep in mind that default logger may expose sensitive information, use in development only
bot, err := telego.NewBot(botToken, telego.WithDefaultDebugLogger())
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Document parameters
document := tu.Document(
// Chat ID as Integer
tu.ID(1234567),
// Send using file from disk
tu.File(mustOpen("my_file.txt")),
// Send using external URL
// tu.FileFromURL("https://example.com/my_file.txt"),
// Send using file ID
// tu.FileFromID("<file ID of your file>"),
).WithCaption("My cool file from disk")
// Sending document
msg, err := bot.SendDocument(document)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(msg.Document)
// =========================================== //
// Photo parameters
photo := tu.Photo(
// Chat ID as String (target username)
tu.Username("@my_cool_channel"),
// Send using file from disk
tu.File(mustOpen("my_photo.png")),
).WithCaption("My cool photo")
// Sending photo
_, _ = bot.SendPhoto(photo)
// =========================================== //
// Media group parameters
mediaGroup := tu.MediaGroup(
tu.ID(1234567),
// Specify a slice of telego.InputMedia with media you want to send as a group
tu.MediaPhoto(tu.File(mustOpen("my_photo.png"))),
tu.MediaPhoto(tu.FileFromID("<file ID of your photo>")),
tu.MediaPhoto(tu.FileFromURL("https://example.com/my_photo.png")),
)
// Sending a media group
_, _ = bot.SendMediaGroup(mediaGroup)
}
// Helper function to open file or panic
func mustOpen(filename string) *os.File {
file, err := os.Open(filename)
if err != nil {
panic(err)
}
return file
}