-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample_test.go
66 lines (59 loc) · 1.58 KB
/
example_test.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
package gotelebot_test
import (
"fmt"
"io/ioutil"
"github.com/eternnoir/gotelebot"
)
func Example() {
// Echo Bot example.
bot := gotelebot.InitTeleBot("TOKEN") // Create gotelebot instance
go bot.StartPolling(true, 0) // Start get new message whit goroutine and default timeout.
newMsgChan := bot.Messages
for {
m := <-newMsgChan // Get new messaage, when new message arrive.
if m.Text != "" { // Check message is text message.
bot.SendMessage(int(m.Chat.Id), m.Text, nil)
}
}
}
func ExampleTeleBot_GetMe() {
bot := gotelebot.InitTeleBot("TOKEN") // Create gotelebot instance
me, err := bot.GetMe() // Get user object.
if err != nil {
fmt.Println(err)
return
}
fmt.Println(me.FirstName)
}
func ExampleTeleBot_SendMessage() {
bot := gotelebot.InitTeleBot("TOKEN") // Create gotelebot instance
testMsg := "Test Msg"
chatid := 11111111
_, err := bot.SendMessage(chatid, testMsg, nil)
if err != nil {
fmt.Println("Bot send message error")
}
}
func ExampleTeleBot_SendPhoto() {
bot := gotelebot.InitTeleBot("TOKEN") // Create gotelebot instance
chatid := 11111111
filePath := "./test_data/go.png"
_, err := bot.SendPhoto(chatid, filePath, nil)
if err != nil {
fmt.Println("Bot send Photo error")
}
}
func ExampleTeleBot_DownloadFile() {
token := "TOKEN"
bot := gotelebot.InitTeleBot(token)
fi := "BQADBQADnAMAAsYifgZph-iT9_z_rgI"
file, err := bot.DownloadFile(fi)
if err != nil {
fmt.Println("Bot get File error")
return
}
ferr := ioutil.WriteFile("/tmp/data", *file, 0644)
if ferr != nil {
fmt.Println("Write to File error")
}
}