Add reply to message for TG API
This commit is contained in:
parent
7effa8cf28
commit
d4499c402e
@ -7,11 +7,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type tgChat struct {
|
type tgChat struct {
|
||||||
ID int `json:"id"`
|
ID int64 `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type tgMessage struct {
|
type tgMessage struct {
|
||||||
MessageID int `json:"message_id"`
|
MessageID int64 `json:"message_id"`
|
||||||
Chat tgChat `json:"chat"`
|
Chat tgChat `json:"chat"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
@ -22,8 +22,10 @@ type tgWebhookRequest struct {
|
|||||||
|
|
||||||
type tgWebhookResponse struct {
|
type tgWebhookResponse struct {
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
ChatID int `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
|
ReplyToMessageID int64 `json:"reply_to_message_id"`
|
||||||
|
ParseMode string `json:"parse_mode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func telegramIsCommand(message string, command string) bool {
|
func telegramIsCommand(message string, command string) bool {
|
||||||
@ -44,6 +46,9 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s, _ := json.Marshal(request)
|
||||||
|
println(s)
|
||||||
|
|
||||||
// Do not respond if not a tg Bot command (starting with /)
|
// Do not respond if not a tg Bot command (starting with /)
|
||||||
if len(request.Message.Text) == 0 || request.Message.Text[0] != '/' {
|
if len(request.Message.Text) == 0 || request.Message.Text[0] != '/' {
|
||||||
return
|
return
|
||||||
@ -107,7 +112,9 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) {
|
|||||||
response := &tgWebhookResponse{
|
response := &tgWebhookResponse{
|
||||||
Method: "sendMessage",
|
Method: "sendMessage",
|
||||||
ChatID: request.Message.Chat.ID,
|
ChatID: request.Message.Chat.ID,
|
||||||
Text: strings.TrimSpace(commandResult),
|
Text: "```\n" + strings.TrimSpace(commandResult) + "\n```",
|
||||||
|
ReplyToMessageID: request.Message.MessageID,
|
||||||
|
ParseMode: "Markdown",
|
||||||
}
|
}
|
||||||
err = json.NewEncoder(w).Encode(response)
|
err = json.NewEncoder(w).Encode(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user