feat: Added EscapeMarkdown and Client#SendMarkdownMessage

This commit is contained in:
ptrcnull 2020-10-14 14:08:07 +02:00
parent ba3e7a59c1
commit a814325e9a

View file

@ -7,8 +7,11 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
)
const badChars = "_*[]()~`>#+-=|{}.!"
type Client struct {
Key string
Offset int64
@ -37,6 +40,18 @@ func (c *Client) GetUpdates() (Response, error) {
return res, err
}
func EscapeMarkdown(msg string) string {
for _, char := range badChars {
ch := string(char)
msg = strings.Replace(msg, ch, "\\"+ch, -1)
}
return msg
}
func (c *Client) SendMarkdownMessage(chatId, body string) (*SendMessageResponse, error) {
return c.SendMessage(chatId, body, url.Values{"parse_mode": {"MarkdownV2"}})
}
func (c *Client) SendMessage(chatId, body string, options ...url.Values) (ret *SendMessageResponse, err error) {
values := url.Values{
"chat_id": {chatId},