-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (42 loc) · 1.2 KB
/
main.go
File metadata and controls
50 lines (42 loc) · 1.2 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
43
44
45
46
47
48
49
50
package main
import (
"context"
"time"
"github.com/rs/zerolog/log"
"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"
)
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 exampleUserID int64 = 123456789 // recipient user ID
file, err := bot.Uploads.UploadFile(context.Background(), models.UploadFileReq{
Type: "image",
FilePath: "cmd/examples/assets/file.png",
})
if err != nil {
log.Error().Msgf("UploadFile error: %v", err)
return
}
if file.Token == "" {
log.Warn().Msg("upload success, but file token is empty")
return
}
attachment := models.AttachImage(file.Token, "")
_, err = bot.Messages.SendMessage(context.Background(), models.SendMessageReq{
UserID: exampleUserID,
Attachments: []models.Attachment{attachment},
})
if err != nil {
log.Error().Msgf("Send File Message error: %v", err)
}
log.Info().Msg("File successfully sent to chat!")
}