diff --git a/client.go b/client.go index c8258b2..7f3ce9a 100644 --- a/client.go +++ b/client.go @@ -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},