-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (43 loc) · 1.13 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
53
54
55
56
57
package main
import (
"flag"
"fmt"
"log"
"strings"
"github.com/ayo-awe/quote_bot/quote"
"gopkg.in/telebot.v3"
"gopkg.in/telebot.v3/middleware"
)
type Application struct {
QuoteProvider quote.QuoteProvider
}
func main() {
port := flag.Uint("port", 4000, "An available system port")
webhookUrl := flag.String("webhook_url", "https://webhook.site", "A public url")
token := flag.String("token", "", "A telegram bot token")
flag.Parse()
addr := fmt.Sprintf(":%d", *port)
publicUrl := fmt.Sprintf("%s/%s", strings.TrimSuffix(*webhookUrl, "/"), *token)
poller := &telebot.Webhook{
Endpoint: &telebot.WebhookEndpoint{
PublicURL: publicUrl,
},
Listen: addr,
}
teleConfig := telebot.Settings{
Token: *token,
Poller: poller,
}
bot, err := telebot.NewBot(teleConfig)
if err != nil {
log.Fatal(err)
}
bot.Use(middleware.Logger())
app := &Application{QuoteProvider: quote.NewQuotableProvider()}
bot.Handle("/start", app.StartCommand)
bot.Handle("/quote", app.QuoteCommand)
bot.Handle("/categories", app.ListCategoriesCommand)
bot.Handle("/search", app.SearchCommand)
fmt.Print("Starting quote bot...")
bot.Start()
}