-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (36 loc) · 1.04 KB
/
main.go
File metadata and controls
42 lines (36 loc) · 1.04 KB
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
package main
import (
"context"
"time"
"github.com/green-api/maxbot-api-client-go/pkg/api"
"github.com/green-api/maxbot-api-client-go/pkg/client"
"github.com/green-api/maxbot-api-client-go/pkg/models"
"github.com/rs/zerolog/log"
)
func main() {
bot, err := api.New(client.Config{
BaseURL: "https://platform-api.max.ru",
Token: "YOUR_BOT_TOKEN",
RateLimiter: 25,
Timeout: 30 * time.Second,
})
if err != nil {
log.Fatal().Err(err).Msg("failed to init MAX API")
}
const exampleChatID int64 = 123456789 // recipient user ID
_, err = bot.Helpers.SendFile(context.Background(), models.SendFileReq{
ChatID: exampleChatID,
FileSource: "cmd/examples/assets/file.txt",
})
if err != nil {
log.Error().Err(err).Msg("failed to send local file")
return
}
_, err = bot.Helpers.SendFile(context.Background(), models.SendFileReq{
ChatID: exampleChatID,
FileSource: "https://storage.yandexcloud.net/sw-prod-03-test/ChatBot/corgi.jpg",
})
if err != nil {
log.Error().Err(err).Msg("failed to send file by URL")
}
}