working
This commit is contained in:
parent
454aaf8460
commit
11eccdd3a8
70
main.go
70
main.go
@ -39,8 +39,8 @@ func main() {
|
|||||||
Chat struct {
|
Chat struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
}
|
}
|
||||||
Data string
|
|
||||||
}
|
}
|
||||||
|
Data string
|
||||||
} `json:"callback_query"`
|
} `json:"callback_query"`
|
||||||
}{}
|
}{}
|
||||||
err = json.Unmarshal(body, &update)
|
err = json.Unmarshal(body, &update)
|
||||||
@ -52,24 +52,63 @@ func main() {
|
|||||||
if update.Message != nil {
|
if update.Message != nil {
|
||||||
go sendButtonAndDelete(update.Message.Chat.ID, update.Message.ID, update.Message.Text)
|
go sendButtonAndDelete(update.Message.Chat.ID, update.Message.ID, update.Message.Text)
|
||||||
} else if update.CallbackQuery != nil {
|
} else if update.CallbackQuery != nil {
|
||||||
answerUrl := fmt.Sprintf("https://api.telegram.org/bot%s/answerCallbackQuery?callback_query_id=%stext=ok", apiToken, update.CallbackQuery.ID)
|
go markButtonChecked(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.ID, update.CallbackQuery.Data)
|
||||||
resp, err := http.Get(answerUrl)
|
go answerCallbackQuery(update.CallbackQuery.ID)
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
body, err = io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Println(string(body))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
port := 28923
|
port := 28923
|
||||||
log.Panic(http.ListenAndServe(fmt.Sprintf(":%v", port), nil))
|
log.Panic(http.ListenAndServe(fmt.Sprintf(":%v", port), nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func markButtonChecked(chatID int, messageID int, text string) {
|
||||||
|
url := fmt.Sprintf("https://api.telegram.org/bot%s/editMessageText", apiToken)
|
||||||
|
text = fmt.Sprintf("✓ %s", text)
|
||||||
|
sendMsgFmt := `
|
||||||
|
{
|
||||||
|
"chat_id": "%d",
|
||||||
|
"message_id": "%d",
|
||||||
|
"text": "ok",
|
||||||
|
"reply_markup": {
|
||||||
|
"inline_keyboard": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"text": "%s",
|
||||||
|
"callback_data": "%s"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
sendMsgReq := fmt.Sprintf(sendMsgFmt, chatID, messageID, text, text)
|
||||||
|
resp, err := http.Post(url, "application/json", strings.NewReader(sendMsgReq))
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println(string(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
func answerCallbackQuery(callbackQueryID string) {
|
||||||
|
answerUrl := fmt.Sprintf("https://api.telegram.org/bot%s/answerCallbackQuery?callback_query_id=%stext=ok", apiToken, callbackQueryID)
|
||||||
|
resp, err := http.Get(answerUrl)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println(string(body))
|
||||||
|
}
|
||||||
|
|
||||||
func sendButtonAndDelete(chatID int, messageID int, text string) {
|
func sendButtonAndDelete(chatID int, messageID int, text string) {
|
||||||
url := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", apiToken)
|
url := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", apiToken)
|
||||||
sendMsgFmt := `
|
sendMsgFmt := `
|
||||||
@ -80,18 +119,17 @@ func sendButtonAndDelete(chatID int, messageID int, text string) {
|
|||||||
"inline_keyboard": [[
|
"inline_keyboard": [[
|
||||||
{
|
{
|
||||||
"text": "%s",
|
"text": "%s",
|
||||||
"callback_data": "42"
|
"callback_data": "%s"
|
||||||
}
|
}
|
||||||
]]
|
]]
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
sendMsgReq := fmt.Sprintf(sendMsgFmt, chatID, text)
|
sendMsgReq := fmt.Sprintf(sendMsgFmt, chatID, text, text)
|
||||||
resp, err := http.Post(url, "application/json", strings.NewReader(sendMsgReq))
|
resp, err := http.Post(url, "application/json", strings.NewReader(sendMsgReq))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println(resp)
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user