-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (60 loc) · 1.73 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"log"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
// Rebply keyboard options
var replyKeyboard = tgbotapi.NewReplyKeyboard(
tgbotapi.NewKeyboardButtonRow(
tgbotapi.NewKeyboardButton("Catalog"),
tgbotapi.NewKeyboardButton("My profile"),
tgbotapi.NewKeyboardButton("About this bot"),
),
)
func main() {
// API of telegram bot. You can get it from the BotFather (https://t.me/BotFather)
bot, err := tgbotapi.NewBotAPI("5532916297:AAGl7CvE3hs23M-iq6xoTtmpiKpK5tkASw8")
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
if err != nil {
log.Panic(err)
}
for update := range updates {
if update.CallbackQuery != nil {
fmt.Print(update)
bot.AnswerCallbackQuery(tgbotapi.NewCallback(update.CallbackQuery.ID, update.CallbackQuery.Data))
bot.Send(tgbotapi.NewMessage(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Data))
}
if update.Message != nil {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
// Commands handling (E.g "/start")
switch update.Message.Command() {
case "start":
msg.Text = update.Message.From.FirstName + ", welcome to LoremMarket!"
msg.ReplyMarkup = replyKeyboard
default:
msg.Text = "Invalid response!"
}
// Text handling (E.g "Catalog" or "About")
switch update.Message.Text {
case "Catalog":
msg.Text = "catalog"
case "About":
msg.Text = "about"
case "About this bot":
msg.Text = "some info about this bot"
case "My profile":
msg.Text = "my profile"
}
// Sending the last message
bot.Send(msg)
}
}
}