options: implement message entities option

pull/477/head
Demian 3 years ago
parent 0e4c75404b
commit 50783dccea

@ -267,6 +267,9 @@ type MessageEntity struct {
Language string `json:"language,omitempty"`
}
// Entities is used to set message's text entities as a send option.
type Entities []MessageEntity
// AutoDeleteTimer represents a service message about a change in auto-delete timer settings.
type AutoDeleteTimer struct {
Unixtime int `json:"message_auto_delete_time"`

@ -66,6 +66,9 @@ type SendOptions struct {
// ParseMode controls how client apps render your message.
ParseMode ParseMode
// Entities is a list of special entities that appear in message text, which can be specified instead of parse_mode.
Entities Entities
// DisableContentDetection abilities to disable server-side file content type detection.
DisableContentDetection bool

@ -178,6 +178,11 @@ func extractOptions(how []interface{}) *SendOptions {
opts = &SendOptions{}
}
opts.ParseMode = opt
case Entities:
if opts == nil {
opts = &SendOptions{}
}
opts.Entities = opt
default:
panic("telebot: unsupported send-option")
}
@ -211,6 +216,15 @@ func (b *Bot) embedSendOptions(params map[string]string, opt *SendOptions) {
params["parse_mode"] = opt.ParseMode
}
if len(opt.Entities) > 0 {
entities, _ := json.Marshal(opt.Entities)
if params["caption"] != "" {
params["caption_entities"] = string(entities)
} else {
params["entities"] = string(entities)
}
}
if opt.DisableContentDetection {
params["disable_content_type_detection"] = "true"
}

Loading…
Cancel
Save