-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelegraphist.go
39 lines (31 loc) · 943 Bytes
/
telegraphist.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
package telegraphist
import (
"net/http"
"time"
"github.com/xamut/telegraphist/telegram"
)
const (
// DefaultBaseURL is endpoint URL to Telegram Bot API
DefaultBaseURL string = "https://api.telegram.org/bot"
// DefaultPort is port for serving the webhook
DefaultPort int = 443
// DefaultTimeout is period of time that will be allowed to wait a response
DefaultTimeout time.Duration = 5 * time.Second
)
// ClientConfig represents settings of API client
type ClientConfig struct {
BaseURL string
BotToken string
Timeout time.Duration
}
// NewClient creates a new instance of API client with ClientConfig
func NewClient(config *ClientConfig) (*telegram.Client, error) {
if config.BaseURL == "" {
config.BaseURL = DefaultBaseURL
}
if config.Timeout == 0 {
config.Timeout = DefaultTimeout
}
httpClient := &http.Client{Timeout: config.Timeout}
return telegram.NewClient(config.BaseURL, config.BotToken, httpClient)
}