/
main.go
52 lines (49 loc) · 1.04 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
// echo is a bot that repeats whatever you tell him.
package main
import (
tm "github.com/and3rson/telemux/v2"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
"os"
)
func main() {
bot, err := tgbotapi.NewBotAPI(os.Getenv("TG_TOKEN"))
if err != nil {
log.Fatal(err)
}
bot.Debug = true
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
mux := tm.NewMux().
AddHandler(tm.NewHandler(
tm.IsCommandMessage("start"),
func(u *tm.Update) {
bot.Send(tgbotapi.NewMessage(
u.Message.Chat.ID,
"Hello! I'm a simple bot who repeats everything you say. :)",
))
},
)).
AddHandler(tm.NewHandler(
tm.HasText(),
func(u *tm.Update) {
bot.Send(tgbotapi.NewMessage(
u.Message.Chat.ID,
"You said: "+u.Message.Text,
))
},
)).
AddHandler(tm.NewHandler(
tm.Any(),
func(u *tm.Update) {
bot.Send(tgbotapi.NewMessage(
u.Message.Chat.ID,
"Uh-oh, I can't repeat that!",
))
},
))
for update := range updates {
mux.Dispatch(bot, update)
}
}