forked from mymmrac/telego
/
main.go
71 lines (54 loc) · 2.71 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
package main
import (
"fmt"
"os"
"strings"
"github.com/valyala/fasthttp"
"github.com/dsurl/tgo"
)
func main() {
botToken := os.Getenv("TOKEN")
var myLogger tgo.Logger // Used just for example (not valid in real use)
// Create bot, all options are optional
bot, err := tgo.NewBot(botToken,
// Change bot API server URL (default: https://api.telegram.org)
tgo.WithAPIServer("new bot api server"),
// Change HTTP client (default: &fasthttp.Client{})
tgo.WithFastHTTPClient(&fasthttp.Client{}),
// Enables basic health check that will call getMe method before returning bot instance (default: false)
tgo.WithHealthCheck(),
// Make all warnings an errors for all requests (default: false)
// Note: Things like `deleteWebhook` may return result as true, but also error description with warning
tgo.WithWarnings(),
// Configuration of default logger, enable printing debug information and errors (default: false, true)
// Note: Please keep in mind that default logger may expose sensitive information, use in development only
tgo.WithDefaultLogger(false, true),
// Extended configuration of default logger, enable printing debug information, errors and set replacer
// (default: false, true, default replacer of bot token)
// Note: Please keep in mind that default logger may expose sensitive information, use in development only
tgo.WithExtendedDefaultLogger(true, true, strings.NewReplacer("old", "new")),
// Uses default logger with enabled debug logs, same as tgo.WithDefaultLogger(true, true)
// Note: Please keep in mind that default logger may expose sensitive information, use in development only
tgo.WithDefaultDebugLogger(),
// Uses default logger with disabled debug and errors, same as tgo.WithDefaultLogger(false, false)
tgo.WithDiscardLogger(),
// Create you custom logger that implements tgo.Logger (default: tgo has build in default logger)
// Note: Please keep in mind that logger may expose sensitive information, use in development only or configure
// it not to leak unwanted content
tgo.WithLogger(myLogger),
// Used in combination with tgo.Bot.EmptyValue() to get empty values for string parameters in cases where
// empty parameter is a valid value (default: TGO_EMPTY_VALUE)
// Note: By default no empty value is set, so using tgo.Bot.EmptyValue() does nothing
tgo.WithEmptyValues(),
// Same as tgo.WithEmptyValues(), but you can define your own empty value that will be used
// Note: Request data will be encoded as JSON, so empty value should match it after encoding too
tgo.WithCustomEmptyValues("the_empty_value"),
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Call method getMe
botUser, _ := bot.GetMe()
fmt.Printf("Bot user: %+v\n", botUser)
}