Skip to content

Commit

Permalink
Updated types to Telegram Bot API v7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mymmrac committed Jun 2, 2024
1 parent 3549c38 commit fb691f1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
9 changes: 9 additions & 0 deletions telegoutil/message_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ func (c MessageEntityCollection) Blockquote() MessageEntityCollection {
return c
}

// ExpandableBlockquote assigns expandable blockquote entity and returns new collection
func (c MessageEntityCollection) ExpandableBlockquote() MessageEntityCollection {
c.entities = append(c.entities, telego.MessageEntity{
Type: telego.EntityTypeExpandableBlockquote,
Length: UTF16TextLen(c.text),
})
return c
}

// Code assigns code entity and returns new collection
func (c MessageEntityCollection) Code() MessageEntityCollection {
c.entities = append(c.entities, telego.MessageEntity{
Expand Down
4 changes: 3 additions & 1 deletion telegoutil/message_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ func TestMessageEntities(t *testing.T) {

Entity(text2).CustomEmoji(text1),
Entity(text3).Blockquote(),
Entity(text4).ExpandableBlockquote(),
)

assert.Equal(t, strings.Repeat(text1+text2+text3+text4, 5)+text1+text2+text3, text)
assert.Equal(t, strings.Repeat(text1+text2+text3+text4, 6), text)
assert.Equal(t, []telego.MessageEntity{
{Type: "italic", Offset: 4, Length: 5, URL: "", User: nil, Language: ""},
{Type: "bold", Offset: 9, Length: 5, URL: "", User: nil, Language: ""},
Expand Down Expand Up @@ -97,6 +98,7 @@ func TestMessageEntities(t *testing.T) {
{Type: "email", Offset: 95, Length: 4, URL: "", User: nil, Language: ""},
{Type: "custom_emoji", Offset: 99, Length: 5, URL: "", User: nil, Language: "", CustomEmojiID: text1},
{Type: "blockquote", Offset: 104, Length: 5, URL: "", User: nil, Language: ""},
{Type: "expandable_blockquote", Offset: 109, Length: 5, URL: "", User: nil, Language: ""},
}, entities)

t.Run("non_ascii", func(t *testing.T) {
Expand Down
37 changes: 19 additions & 18 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,24 +941,25 @@ type MessageEntity struct {

// MessageEntity types
const (
EntityTypeMention = "mention"
EntityTypeHashtag = "hashtag"
EntityTypeCashtag = "cashtag"
EntityTypeBotCommand = "bot_command"
EntityTypeURL = "url"
EntityTypeEmail = "email"
EntityTypePhoneNumber = "phone_number"
EntityTypeBold = "bold"
EntityTypeItalic = "italic"
EntityTypeUnderline = "underline"
EntityTypeStrikethrough = "strikethrough"
EntityTypeSpoiler = "spoiler"
EntityTypeBlockquote = "blockquote"
EntityTypeCode = "code"
EntityTypePre = "pre"
EntityTypeTextLink = "text_link"
EntityTypeTextMention = "text_mention"
EntityTypeCustomEmoji = "custom_emoji"
EntityTypeMention = "mention"
EntityTypeHashtag = "hashtag"
EntityTypeCashtag = "cashtag"
EntityTypeBotCommand = "bot_command"
EntityTypeURL = "url"
EntityTypeEmail = "email"
EntityTypePhoneNumber = "phone_number"
EntityTypeBold = "bold"
EntityTypeItalic = "italic"
EntityTypeUnderline = "underline"
EntityTypeStrikethrough = "strikethrough"
EntityTypeSpoiler = "spoiler"
EntityTypeBlockquote = "blockquote"
EntityTypeExpandableBlockquote = "expandable_blockquote"
EntityTypeCode = "code"
EntityTypePre = "pre"
EntityTypeTextLink = "text_link"
EntityTypeTextMention = "text_mention"
EntityTypeCustomEmoji = "custom_emoji"
)

// TextQuote - This object contains information about the quoted part of a message that is replied to by the
Expand Down
4 changes: 2 additions & 2 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ func TestTypesConstants(t *testing.T) {
{
EntityTypeMention, EntityTypeHashtag, EntityTypeCashtag, EntityTypeBotCommand, EntityTypeURL,
EntityTypeEmail, EntityTypePhoneNumber, EntityTypeBold, EntityTypeItalic, EntityTypeUnderline,
EntityTypeStrikethrough, EntityTypeSpoiler, EntityTypeBlockquote, EntityTypeCode, EntityTypePre,
EntityTypeTextLink, EntityTypeTextMention, EntityTypeCustomEmoji,
EntityTypeStrikethrough, EntityTypeSpoiler, EntityTypeBlockquote, EntityTypeExpandableBlockquote,
EntityTypeCode, EntityTypePre, EntityTypeTextLink, EntityTypeTextMention, EntityTypeCustomEmoji,
},
{
OriginTypeUser, OriginTypeHiddenUser, OriginTypeChat, OriginTypeChannel,
Expand Down

0 comments on commit fb691f1

Please sign in to comment.