diff --git a/client.go b/client.go index 58b4308..9186549 100644 --- a/client.go +++ b/client.go @@ -364,6 +364,10 @@ func (c *Client) SendTextMessage(message *Message) error { params.Set("inlineKeyboardMarkup", string(data)) } + if message.ParseMode != "" { + params.Set("parseMode", string(message.ParseMode)) + } + response, err := c.Do("/messages/sendText", params, nil) if err != nil { return fmt.Errorf("error while sending text: %s", err) @@ -392,6 +396,10 @@ func (c *Client) EditMessage(message *Message) error { params.Set("inlineKeyboardMarkup", string(data)) } + if message.ParseMode != "" { + params.Set("parseMode", string(message.ParseMode)) + } + response, err := c.Do("/messages/editText", params, nil) if err != nil { return fmt.Errorf("error while editing text: %s", err) @@ -442,6 +450,10 @@ func (c *Client) SendFileMessage(message *Message) error { params.Set("inlineKeyboardMarkup", string(data)) } + if message.ParseMode != "" { + params.Set("parseMode", string(message.ParseMode)) + } + response, err := c.Do("/messages/sendFile", params, nil) if err != nil { return fmt.Errorf("error while making request: %s", err) diff --git a/message.go b/message.go index 48fedfc..ad3e788 100644 --- a/message.go +++ b/message.go @@ -54,6 +54,9 @@ type Message struct { // The markup for the inline keyboard InlineKeyboard *Keyboard `json:"inlineKeyboardMarkup"` + + // The parse mode (HTML/MarkdownV2) + ParseMode ParseMode `json:"parseMode"` } func (m *Message) AttachNewFile(file *os.File) { @@ -76,6 +79,19 @@ func (m *Message) AttachExistingVoice(fileID string) { m.ContentType = Voice } +// ParseMode represent a type of text formatting +type ParseMode string + +const ( + ParseModeHTML ParseMode = "HTML" + ParseModeMarkdownV2 ParseMode = "MarkdownV2" +) + +// AppendParseMode append a type of text formatting for current message +func (m *Message) AppendParseMode(mode ParseMode) { + m.ParseMode = mode +} + // AttachInlineKeyboard adds a keyboard to the message. // Note - at least one row should be in the keyboard // and there should be no empty rows diff --git a/message_easyjson.go b/message_easyjson.go index 4ce23b7..72f7b82 100644 --- a/message_easyjson.go +++ b/message_easyjson.go @@ -64,6 +64,8 @@ func easyjson4086215fDecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Mes } easyjson4086215fDecodeGithubComMailRuImBotGolang1(in, out.InlineKeyboard) } + case "parseMode": + out.ParseMode = ParseMode(in.String()) default: in.SkipRecursive() } @@ -132,6 +134,11 @@ func easyjson4086215fEncodeGithubComMailRuImBotGolang(out *jwriter.Writer, in Me easyjson4086215fEncodeGithubComMailRuImBotGolang1(out, *in.InlineKeyboard) } } + { + const prefix string = ",\"parseMode\":" + out.RawString(prefix) + out.String(string(in.ParseMode)) + } out.RawByte('}') } diff --git a/types_easyjson.go b/types_easyjson.go index 7fc1187..1b824f5 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -822,12 +822,6 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev continue } switch key { - case "queryId": - out.QueryID = string(in.String()) - case "message": - (out.CallbackMsg).UnmarshalEasyJSON(in) - case "callbackData": - out.CallbackData = string(in.String()) case "parts": if in.IsNull() { in.Skip() @@ -851,6 +845,12 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev } in.Delim(']') } + case "queryId": + out.QueryID = string(in.String()) + case "message": + (out.CallbackMsg).UnmarshalEasyJSON(in) + case "callbackData": + out.CallbackData = string(in.String()) case "leftMembers": if in.IsNull() { in.Skip() @@ -925,24 +925,9 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(out *jwriter.Writer, in E out.RawByte('{') first := true _ = first - { - const prefix string = ",\"queryId\":" - out.RawString(prefix[1:]) - out.String(string(in.QueryID)) - } - { - const prefix string = ",\"message\":" - out.RawString(prefix) - (in.CallbackMsg).MarshalEasyJSON(out) - } - { - const prefix string = ",\"callbackData\":" - out.RawString(prefix) - out.String(string(in.CallbackData)) - } { const prefix string = ",\"parts\":" - out.RawString(prefix) + out.RawString(prefix[1:]) if in.Parts == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { out.RawString("null") } else { @@ -956,6 +941,21 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(out *jwriter.Writer, in E out.RawByte(']') } } + { + const prefix string = ",\"queryId\":" + out.RawString(prefix) + out.String(string(in.QueryID)) + } + { + const prefix string = ",\"message\":" + out.RawString(prefix) + (in.CallbackMsg).MarshalEasyJSON(out) + } + { + const prefix string = ",\"callbackData\":" + out.RawString(prefix) + out.String(string(in.CallbackData)) + } { const prefix string = ",\"leftMembers\":" out.RawString(prefix)