-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
main.go
51 lines (45 loc) · 1.25 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
package main
import (
"fmt"
"os"
"time"
"github.com/mymmrac/telego"
ta "github.com/mymmrac/telego/telegoapi"
)
func main() {
// Get Bot token from environment variables
botToken := os.Getenv("TOKEN")
// Create bot and enable debugging info
// (more on configuration in /examples/configuration/main.go)
// Note: Please keep in mind that default logger may expose sensitive information, use in development only
bot, err := telego.NewBot(
botToken,
// Set up retry caller
telego.WithAPICaller(&ta.RetryCaller{
// Use caller
Caller: ta.DefaultFastHTTPCaller,
// Max number of attempts to make call
MaxAttempts: 4,
// Exponent base for delay
ExponentBase: 2,
// Starting delay duration
StartDelay: time.Millisecond * 10,
// Maximum delay duration
MaxDelay: time.Second,
}),
telego.WithDefaultDebugLogger(),
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Call method getMe (https://core.telegram.org/bots/api#getme).
// In case if this call will fail, retry caller will retry calling Telegram until request is
// successful (no network errors) or max attempts reached.
botUser, err := bot.GetMe()
if err != nil {
fmt.Println("Error:", err)
}
// Print Bot information
fmt.Printf("Bot user: %+v\n", botUser)
}