Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bots-go-framework/bots-api-telegram
go 1.25

require (
github.com/bots-go-framework/bots-go-core v0.2.5
github.com/bots-go-framework/bots-go-core v0.2.6
github.com/stretchr/testify v1.11.1
github.com/strongo/logus v0.4.1
github.com/technoweenie/multipartstreamer v1.0.1
Expand Down
22 changes: 2 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
github.com/bots-go-framework/bots-go-core v0.1.0 h1:mZZ0QC/CfvsLufYjkJR+nYeXkbNEJ5IXwAn2noxpzTE=
github.com/bots-go-framework/bots-go-core v0.1.0/go.mod h1:XCn9z4TI8sbgwyus+VDzw7iMY2QCPWEAvl23GMDjeEU=
github.com/bots-go-framework/bots-go-core v0.2.1 h1:LN2575Fv+441LSQWae+R8nZzt1JbGRdVK1SP2Yt4Skk=
github.com/bots-go-framework/bots-go-core v0.2.1/go.mod h1:XCn9z4TI8sbgwyus+VDzw7iMY2QCPWEAvl23GMDjeEU=
github.com/bots-go-framework/bots-go-core v0.2.2 h1:9Wi8L4Y1sCpHiYAVejgXkwrezwk2r2yIF9I3IG3iJzc=
github.com/bots-go-framework/bots-go-core v0.2.2/go.mod h1:XCn9z4TI8sbgwyus+VDzw7iMY2QCPWEAvl23GMDjeEU=
github.com/bots-go-framework/bots-go-core v0.2.3 h1:wqdeyDJ+f+3W0RyFu7h46dkHoXoa74mOltmCM6W0tQc=
github.com/bots-go-framework/bots-go-core v0.2.3/go.mod h1:XCn9z4TI8sbgwyus+VDzw7iMY2QCPWEAvl23GMDjeEU=
github.com/bots-go-framework/bots-go-core v0.2.4 h1:ppsw1MohTCFIDjp5tmccAokRAeq2PcuhNQooxsN4fFc=
github.com/bots-go-framework/bots-go-core v0.2.4/go.mod h1:XCn9z4TI8sbgwyus+VDzw7iMY2QCPWEAvl23GMDjeEU=
github.com/bots-go-framework/bots-go-core v0.2.5 h1:Uv9zb23yHJY/GnfEF6ocucAmfS12pwFHiig29ZoSqME=
github.com/bots-go-framework/bots-go-core v0.2.5/go.mod h1:O/J3Q4HhTpbsbCL87Zhlf1BPtvfVp9UcfBWsc8D8ghw=
github.com/bots-go-framework/bots-go-core v0.2.6 h1:OnDcCNXWLhZAiK9kvwfHOi1wnI6P13r9Qp5q295T4So=
github.com/bots-go-framework/bots-go-core v0.2.6/go.mod h1:O/J3Q4HhTpbsbCL87Zhlf1BPtvfVp9UcfBWsc8D8ghw=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -25,16 +15,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8=
github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/strongo/logus v0.2.1 h1:ZzAtdSg6PPF1Y43WbNWl7MH1XYl7kvKMxyxv/lpbadI=
github.com/strongo/logus v0.2.1/go.mod h1:sd8gjJklqGQAg+Q0mlP5MWgzguAuxR25YYFSkfVOPdc=
github.com/strongo/logus v0.4.0 h1:EdwNafWX1eGWvPqMvu3gHVqXtBOUvV9KWbxm6tCU+dU=
github.com/strongo/logus v0.4.0/go.mod h1:sd8gjJklqGQAg+Q0mlP5MWgzguAuxR25YYFSkfVOPdc=
github.com/strongo/logus v0.4.1 h1:jEkcT5JzawDYjexRVHkCQiG4tv6Bm2a/c/ZdLk0IPqM=
github.com/strongo/logus v0.4.1/go.mod h1:sd8gjJklqGQAg+Q0mlP5MWgzguAuxR25YYFSkfVOPdc=
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
Expand Down
20 changes: 11 additions & 9 deletions tgbotapi/api_v10_0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,31 @@ func TestUpdateGuestMessage(t *testing.T) {
// TestSentGuestMessage verifies round-tripping of the SentGuestMessage class returned by
// answerGuestQuery (Bot API 10.0).
func TestSentGuestMessage(t *testing.T) {
data := `{"message_id": 55}`
data := `{"inline_message_id": "guest-inline-55"}`
var sent SentGuestMessage
require.NoError(t, json.Unmarshal([]byte(data), &sent))
assert.Equal(t, 55, sent.MessageID)
assert.Equal(t, "guest-inline-55", sent.InlineMessageID)
}

// TestBotAccessSettings verifies round-tripping of BotAccessSettings, used by
// getManagedBotAccessSettings/setManagedBotAccessSettings (Bot API 10.0).
func TestBotAccessSettings(t *testing.T) {
settings := BotAccessSettings{
CanReadMessages: true,
CanSendMessages: true,
CanManageSettings: false,
IsAccessRestricted: true,
AddedUsers: []User{
{ID: 42, FirstName: "Player"},
},
}

data, err := encodeToJson(settings)
require.NoError(t, err)

var decoded map[string]any
var decoded BotAccessSettings
require.NoError(t, json.Unmarshal(data, &decoded))
assert.Equal(t, true, decoded["can_read_messages"])
assert.Equal(t, true, decoded["can_send_messages"])
assert.NotContains(t, decoded, "can_manage_settings")
assert.True(t, decoded.IsAccessRestricted)
require.Len(t, decoded.AddedUsers, 1)
assert.EqualValues(t, 42, decoded.AddedUsers[0].ID)
assert.Equal(t, "Player", decoded.AddedUsers[0].FirstName)
}

// TestLivePhotoUnmarshal verifies parsing of the LivePhoto class (Bot API 10.0 Live Photos).
Expand Down
86 changes: 84 additions & 2 deletions tgbotapi/api_v10_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,100 @@ func TestRichTextCustomEmoji(t *testing.T) {

// TestRichTextDateTime verifies RichTextDateTime's unix_time and date_time_format fields.
func TestRichTextDateTime(t *testing.T) {
data := `{"type": "date_time", "text": "yesterday", "unix_time": 1700000000, "date_time_format": "relative"}`
data := `{"type": "date_time", "text": "yesterday", "unix_time": 1700000000, "date_time_format": "r"}`
var rt RichText
require.NoError(t, json.Unmarshal([]byte(data), &rt))
assert.Equal(t, RichTextTypeDateTime, rt.Type)
assert.Equal(t, 1700000000, rt.UnixTime)
assert.Equal(t, "relative", rt.DateTimeFormat)
assert.Equal(t, "r", rt.DateTimeFormat)

out, err := json.Marshal(rt)
require.NoError(t, err)
assert.JSONEq(t, data, string(out))
}

func TestRichTextDateTimeFormatValidate(t *testing.T) {
tests := []struct {
name string
format string
wantErr bool
}{
{name: "relative", format: "r"},
{name: "weekday", format: "w"},
{name: "short date", format: "d"},
{name: "long date", format: "D"},
{name: "short time", format: "t"},
{name: "long time", format: "T"},
{name: "weekday short date", format: "wd"},
{name: "weekday long date", format: "wD"},
{name: "weekday short time", format: "wt"},
{name: "weekday long time", format: "wT"},
{name: "short date short time", format: "dt"},
{name: "short date long time", format: "dT"},
{name: "long date short time", format: "Dt"},
{name: "long date long time", format: "DT"},
{name: "weekday short date short time", format: "wdt"},
{name: "weekday short date long time", format: "wdT"},
{name: "weekday long date short time", format: "wDt"},
{name: "weekday long date long time", format: "wDT"},
{name: "empty", format: ""},
{name: "word alias", format: "relative", wantErr: true},
{name: "uppercase relative", format: "R", wantErr: true},
{name: "relative with date", format: "rd", wantErr: true},
{name: "date before weekday", format: "dw", wantErr: true},
{name: "time before date", format: "td", wantErr: true},
{name: "duplicate date", format: "dd", wantErr: true},
{name: "duplicate time", format: "TT", wantErr: true},
{name: "surrounding whitespace", format: " r ", wantErr: true},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rt := RichText{
Type: RichTextTypeDateTime,
Text: &RichText{PlainText: "when"},
UnixTime: 1_700_000_000,
DateTimeFormat: tt.format,
}
err := rt.Validate()
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})
}
}

func TestRichTextDateTimeRequiredZeroValuesArePresentOnWire(t *testing.T) {
rt := RichText{
Type: RichTextTypeDateTime,
Text: &RichText{PlainText: "when"},
}
require.NoError(t, rt.Validate())

data, err := json.Marshal(rt)
require.NoError(t, err)
assert.JSONEq(t, `{
"type": "date_time",
"text": "when",
"unix_time": 0,
"date_time_format": ""
}`, string(data))
}

func TestRichTextDateTimeFieldsAreOmittedForOtherVariants(t *testing.T) {
rt := RichText{
Type: RichTextTypeBold,
Text: &RichText{PlainText: "bold"},
}

data, err := json.Marshal(rt)
require.NoError(t, err)
assert.NotContains(t, string(data), "date_time_format")
assert.NotContains(t, string(data), "unix_time")
}

// TestRichBlockParagraph verifies RichBlockParagraph JSON round-tripping via the flattened RichBlock struct.
func TestRichBlockParagraph(t *testing.T) {
data := `{"type": "paragraph", "text": "hello"}`
Expand Down
Loading