-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (33 loc) · 895 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
package main
import (
"log"
"telegram.api/telegram_youtube/youtube"
tel "github.com/go-telegram-bot-api/telegram-bot-api"
)
func main() {
bot, err := tel.NewBotAPI("There will be your token")
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tel.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
if err != nil {
log.Panic(err)
}
for update := range updates {
if update.Message == nil {
continue
}
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
// msg := tel.NewMessage(update.Message.Chat.ID, update.Message.Text)
videoUrl, err := youtube.GetLastVideo(update.Message.Text, 1)
if err != nil {
log.Println(err)
}
bot.Send(tel.NewMessage(update.Message.Chat.ID, err.Error()))
bot.Send(tel.NewMessage(update.Message.Chat.ID, videoUrl))
}
}