Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
112 lines (104 loc) · 4.08 KB
/
Copy pathmain.go
File metadata and controls
112 lines (104 loc) · 4.08 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"log"
)
const discId int64 = -1002485069399
func main() {
showKeyboard := true
start := false
// Создаем новый объект бота с токеном
bot, err := tgbotapi.NewBotAPI("8150718493:AAEVPOHYd_4l3R4wmyr6GkSXPMt3RU8NVBI")
if err != nil {
log.Panic(err)
}
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, _ := bot.GetUpdatesChan(u)
// Создаем кастомную клавиатуру
customKeyboard := tgbotapi.NewReplyKeyboard(
tgbotapi.NewKeyboardButtonRow(
tgbotapi.NewKeyboardButton("Отправить заявку администратору"),
tgbotapi.NewKeyboardButton("Наши отзывы"),
),
tgbotapi.NewKeyboardButtonRow(
tgbotapi.NewKeyboardButton("Часто задаваемые вопросы"),
),
)
for update := range updates {
if update.Message.Chat.ID != discId {
if update.Message == nil {
continue
}
if update.Message.Text == "/start" {
start = true
}
fmt.Printf("[%s] %s\n", update.Message.From.UserName, update.Message.Text)
if update.Message != nil && start {
if update.Message.Text == "Отправить заявку администратору" {
showKeyboard = false
msgToDisc := tgbotapi.NewMessage(discId, "Клиент хочет, чтобы с ним связался администратор!")
urlButton := tgbotapi.NewInlineKeyboardButtonURL("Клиент", fmt.Sprintf("tg://user?id=%d", update.Message.Chat.ID))
inlineKeyboard := tgbotapi.NewInlineKeyboardMarkup(tgbotapi.NewInlineKeyboardRow(urlButton))
msgToDisc.ReplyMarkup = inlineKeyboard
if _, err := bot.Send(msgToDisc); err != nil {
panic(err)
}
msgToClient := tgbotapi.NewMessage(update.Message.Chat.ID, "Заявка успешно отправлена. Администратор скоро свяжется с вами.")
// Отправляем сообщение в Telegram
if _, err := bot.Send(msgToClient); err != nil {
panic(err)
}
} else if update.Message.Text == "Наши отзывы" {
// Создаем inline-клавиатуру
showKeyboard = false
urlButton := tgbotapi.NewInlineKeyboardButtonURL("Отзывы", "https://t.me/feedback_Livs")
inlineKeyboard := tgbotapi.NewInlineKeyboardMarkup(tgbotapi.NewInlineKeyboardRow(urlButton))
msgToClient := tgbotapi.NewMessage(update.Message.Chat.ID, "Наши отзывы:")
msgToClient.ReplyMarkup = inlineKeyboard
// Отправляем сообщение в Telegram
if _, err := bot.Send(msgToClient); err != nil {
panic(err)
}
} else if update.Message.Text == "Часто задаваемые вопросы" {
showKeyboard = false
msgToClient := tgbotapi.NewMessage(update.Message.Chat.ID, "Ответ на вопрос")
if _, err := bot.Send(msgToClient); err != nil {
panic(err)
}
} else if update.Message.Text == "Да" {
showKeyboard = true
} else if update.Message.Text == "Нет" {
showKeyboard = false
msgToClient := tgbotapi.NewMessage(update.Message.Chat.ID, "Чтобы снова начать работу бота, напишите /start")
start = false
msgToClient.ReplyMarkup = tgbotapi.NewRemoveKeyboard(true)
if _, err := bot.Send(msgToClient); err != nil {
panic(err)
}
continue
}
if showKeyboard {
msgToClient := tgbotapi.NewMessage(update.Message.Chat.ID, "Выберите кнопку:")
msgToClient.ReplyMarkup = customKeyboard
if _, err := bot.Send(msgToClient); err != nil {
panic(err)
}
} else {
msgToClient := tgbotapi.NewMessage(update.Message.Chat.ID, "Продолжить?")
customKeyboardYesOrNot := tgbotapi.NewReplyKeyboard(
tgbotapi.NewKeyboardButtonRow(
tgbotapi.NewKeyboardButton("Да"),
tgbotapi.NewKeyboardButton("Нет"),
),
)
msgToClient.ReplyMarkup = customKeyboardYesOrNot
if _, err := bot.Send(msgToClient); err != nil {
panic(err)
}
}
}
}
}
}