-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (40 loc) · 956 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/lanseg/tgbot"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: ./main <bot_api_key>")
os.Exit(1)
}
bot, err := tgbot.NewBot(os.Args[1])
if err != nil {
fmt.Printf("Error while creating bot: %s\n", err)
os.Exit(1)
}
api := tgbot.NewTelegramApi(bot)
result, err := api.GetUpdates(&tgbot.GetUpdatesRequest{
Timeout: 60, // 60 Seconds
})
if err != nil {
fmt.Printf("Could not perform request: %s\n", err)
os.Exit(1)
}
for _, upd := range result.Result {
msg := upd.Message
fmt.Printf("Got new message %d in chat %d: %s\n", msg.MessageID, msg.Chat.ID, msg.Text)
result, err := api.SetMessageReaction(&tgbot.SetMessageReactionRequest{
MessageID: msg.MessageID,
ChatID: fmt.Sprintf("%d", msg.Chat.ID),
Reaction: []*tgbot.ReactionType{
{
Type: "emoji",
Emoji: "❤",
},
},
})
fmt.Printf("Got a response: %s: %s", result, err)
}
}