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
46 changes: 46 additions & 0 deletions bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
const (
TestToken = "153667468:AAHlSHlMqSt1f_uFmVRJbm5gntu2HI4WW8I"
ChatID = 76918703
Channel = "@tgbotapitest"
SupergroupChatID = -1001120141283
ReplyToMessageID = 35
ExistingPhotoFileID = "AgADAgADw6cxG4zHKAkr42N7RwEN3IFShCoABHQwXEtVks4EH2wBAAEC"
Expand Down Expand Up @@ -153,6 +154,51 @@ func TestSendWithNewPhotoReply(t *testing.T) {
}
}

func TestSendNewPhotoToChannel(t *testing.T) {
bot, _ := getBot(t)

msg := NewPhotoUploadToChannel(Channel, "tests/image.jpg")
msg.Caption = "Test"
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}

func TestSendNewPhotoToChannelFileBytes(t *testing.T) {
bot, _ := getBot(t)

data, _ := ioutil.ReadFile("tests/image.jpg")
b := FileBytes{Name: "image.jpg", Bytes: data}

msg := NewPhotoUploadToChannel(Channel, b)
msg.Caption = "Test"
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}

func TestSendNewPhotoToChannelFileReader(t *testing.T) {
bot, _ := getBot(t)

f, _ := os.Open("tests/image.jpg")
reader := FileReader{Name: "image.jpg", Reader: f, Size: -1}

msg := NewPhotoUploadToChannel(Channel, reader)
msg.Caption = "Test"
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}

func TestSendWithExistingPhoto(t *testing.T) {
bot, _ := getBot(t)

Expand Down
18 changes: 18 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ func NewPhotoUpload(chatID int64, file interface{}) PhotoConfig {
}
}

// NewPhotoUploadToChannel creates a new photo uploader to send a photo to a channel.
//
// username is the username of the channel, file is a string path to the file,
// FileReader, or FileBytes.
//
// Note that you must send animated GIFs as a document.
func NewPhotoUploadToChannel(username string, file interface{}) PhotoConfig {
return PhotoConfig{
BaseFile: BaseFile{
BaseChat: BaseChat{
ChannelUsername: username,
},
File: file,
UseExisting: false,
},
}
}

// NewPhotoShare shares an existing photo.
// You may use this to reshare an existing photo without reuploading it.
//
Expand Down