diff --git a/bot.go b/bot.go index c6ca084..bb903b5 100644 --- a/bot.go +++ b/bot.go @@ -307,6 +307,20 @@ func (bot *BotAPI) Send(c Chattable) (Message, error) { return message, err } +// helper to get raw params +func (bot *BotAPI) PreviewParams(c Chattable) (map[string]string, error) { + paramsMap := make(map[string]string) + params, err := c.params() + if params == nil { + return paramsMap, err + } + + for key, value := range params { + paramsMap[key] = value + } + return paramsMap, nil +} + // SendMediaGroup sends a media group and returns the resulting messages. func (bot *BotAPI) SendMediaGroup(config MediaGroupConfig) ([]Message, error) { params, _ := config.params() diff --git a/go.mod b/go.mod index b63227e..05e888f 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/go-telegram-bot-api/telegram-bot-api/v5 +module github.com/temamagic/telegram-bot-api require github.com/technoweenie/multipartstreamer v1.0.1 diff --git a/types.go b/types.go index 78ebcf3..76d4024 100644 --- a/types.go +++ b/types.go @@ -7,6 +7,7 @@ import ( "net/url" "strings" "time" + "unicode/utf16" ) // APIResponse is a response from the Telegram API with the result @@ -270,6 +271,20 @@ func (entity MessageEntity) ParseURL() (*url.URL, error) { return url.Parse(entity.URL) } +// GetEntityText attempts to get entity text value from utf16. +func (m *Message) GetEntityText(entity MessageEntity) string { + if m.Text == "" { + return "" + } + // Encode it into utf16 + utfEncodedString := utf16.Encode([]rune(m.Text)) + runeString := utf16.Decode(utfEncodedString[entity.Offset : entity.Offset+entity.Length]) + // Transform []rune into string + str := string(runeString) + + return str +} + // PhotoSize contains information about photos. type PhotoSize struct { FileID string `json:"file_id"`