Skip to content
Open
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
16 changes: 16 additions & 0 deletions methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,22 @@ func TestBot_Methods(t *testing.T) {
assertTrue(t, resp)
})

t.Run("SetChatMemberTag", func(t *testing.T) {
c := &httpClient{t: t, resp: `true`, reqFields: map[string]string{
"chat_id": "123",
"user_id": "456",
"tag": "moderator",
}}
b := &Bot{client: c}
resp, err := b.SetChatMemberTag(context.Background(), &SetChatMemberTagParams{
ChatID: 123,
UserID: 456,
Tag: "moderator",
})
assertNoErr(t, err)
assertTrue(t, resp)
})

t.Run("BanChatSenderChat", func(t *testing.T) {
c := &httpClient{t: t, resp: `true`, reqFields: map[string]string{
"chat_id": "123",
Expand Down
15 changes: 15 additions & 0 deletions models/web_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@ type WebAppInfo struct {
type SentWebAppMessage struct {
InlineMessageID string `json:"inline_message_id"`
}

// BottomButton https://core.telegram.org/bots/webapps#bottombutton
// Describes the main or secondary button at the bottom of the Mini App (Telegram.WebApp.MainButton / SecondaryButton).
type BottomButton struct {
Type string `json:"type,omitempty"`
IconCustomEmojiID string `json:"iconCustomEmojiId,omitempty"`
Text string `json:"text,omitempty"`
Color string `json:"color,omitempty"`
TextColor string `json:"textColor,omitempty"`
IsVisible bool `json:"isVisible,omitempty"`
IsActive bool `json:"isActive,omitempty"`
HasShineEffect bool `json:"hasShineEffect,omitempty"`
Position string `json:"position,omitempty"`
IsProgressVisible bool `json:"isProgressVisible,omitempty"`
}
53 changes: 53 additions & 0 deletions models/web_app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package models

import (
"encoding/json"
"testing"
)

func TestBottomButtonJSON(t *testing.T) {
src := `{"type":"main","iconCustomEmojiId":"123456789","text":"Continue","color":"#aabbcc","textColor":"#112233","isVisible":true,"isActive":true,"hasShineEffect":true,"position":"left","isProgressVisible":false}`

var b BottomButton
if err := json.Unmarshal([]byte(src), &b); err != nil {
t.Fatal(err)
}

if b.Type != "main" {
t.Fatalf("Type: got %q", b.Type)
}
if b.IconCustomEmojiID != "123456789" {
t.Fatalf("IconCustomEmojiID: got %q", b.IconCustomEmojiID)
}
if b.Text != "Continue" {
t.Fatalf("Text: got %q", b.Text)
}
if b.Color != "#aabbcc" {
t.Fatalf("Color: got %q", b.Color)
}
if b.TextColor != "#112233" {
t.Fatalf("TextColor: got %q", b.TextColor)
}
if !b.IsVisible || !b.IsActive || !b.HasShineEffect {
t.Fatalf("bools: IsVisible=%v IsActive=%v HasShineEffect=%v", b.IsVisible, b.IsActive, b.HasShineEffect)
}
if b.Position != "left" {
t.Fatalf("Position: got %q", b.Position)
}
if b.IsProgressVisible {
t.Fatal("IsProgressVisible: want false")
}

enc, err := json.Marshal(&b)
if err != nil {
t.Fatal(err)
}

var round BottomButton
if err := json.Unmarshal(enc, &round); err != nil {
t.Fatal(err)
}
if round != b {
t.Fatalf("round-trip mismatch: %+v vs %+v", round, b)
}
}