/
main.go
46 lines (43 loc) · 1023 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
// private_only is a bot that allows you to talk to him only in private chat.
package main
import (
tm "github.com/and3rson/telemux"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"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, err := bot.GetUpdatesChan(u)
if err != nil {
log.Fatal(err)
}
mux := tm.NewMux().
AddHandler(tm.NewHandler(
tm.And(tm.IsPrivate(), tm.IsCommandMessage("start")),
func(u *tm.Update) {
bot.Send(tgbotapi.NewMessage(
u.Message.Chat.ID,
"Psst... Don't tell anyone about our private chat! :)",
))
},
)).
AddHandler(tm.NewHandler(
tm.IsCommandMessage("start"),
func(u *tm.Update) {
bot.Send(tgbotapi.NewMessage(
u.Message.Chat.ID,
"Sorry, I only respond in private chats. Send me a direct message!",
))
},
))
for update := range updates {
mux.Dispatch(bot, update)
}
}