-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
61 lines (52 loc) · 1.5 KB
/
app.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
53
54
55
56
57
58
59
60
61
package main
import (
"log"
"github.com/artemzi/summarizer"
"github.com/artemzi/telegram-bot/bot"
"github.com/asaskevich/govalidator"
"gopkg.in/telegram-bot-api.v4"
)
func main() {
app, updates := bot.Run()
for update := range updates {
log.Printf("[%s] %+v\n", update.Message.From, update.Message.Text)
if update.Message.IsCommand() {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "")
switch update.Message.Command() {
case "help":
msg.Text = `
Please paste valid English article URL for bot.
You can use /status command for bot status.
`
case "start":
msg.Text = "Hello I'm ready to help you."
case "status":
msg.Text = "I'm ok."
default:
msg.Text = "I don't know that command"
}
app.Send(msg)
continue
}
if govalidator.IsRequestURL(update.Message.Text) { // if valid URL string
s := summarizer.CreateFromURL(update.Message.Text)
summary, err := s.Summarize()
if err != nil {
log.Println("Error occurred: ", err.Error())
}
summaryInfo, err := s.GetSummaryInfo()
if err != nil {
log.Println("Error occurred: ", err.Error())
}
msg := tgbotapi.NewMessage(update.Message.Chat.ID, summary)
msgInfo := tgbotapi.NewMessage(update.Message.Chat.ID, summaryInfo)
app.Send(msg)
app.Send(msgInfo)
} else {
log.Printf("Wrong url %s", update.Message.Text)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Please provide valid URL string.")
msg.ReplyToMessageID = update.Message.MessageID
app.Send(msg)
}
}
}