-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add models.ParseModeMarkdownV1 const * fix typo in readme * add method SendPaidMedia * add field PaidMedia * add InvoicePayload to TransactionPartnerUser * add PaidMedia * remove comments from example * add refunded_payment * changelog, readme
- Loading branch information
Showing
16 changed files
with
390 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"embed" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/go-telegram/bot" | ||
"github.com/go-telegram/bot/models" | ||
) | ||
|
||
func main() { | ||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) | ||
defer cancel() | ||
|
||
opts := []bot.Option{ | ||
bot.WithDefaultHandler(handler), | ||
} | ||
|
||
b, err := bot.New(os.Getenv("EXAMPLE_TELEGRAM_BOT_TOKEN"), opts...) | ||
if nil != err { | ||
// panics for the sake of simplicity. | ||
// you should handle this error properly in your code. | ||
panic(err) | ||
} | ||
|
||
b.Start(ctx) | ||
} | ||
|
||
//go:embed images | ||
var images embed.FS | ||
|
||
func handler(ctx context.Context, b *bot.Bot, update *models.Update) { | ||
fileDataFacebook, _ := images.ReadFile("images/facebook.png") | ||
fileDataYoutube, _ := images.ReadFile("images/youtube.png") | ||
|
||
if update.ChannelPost == nil { | ||
fmt.Printf("expect channel post\n") | ||
return | ||
} | ||
|
||
chatID := update.ChannelPost.Chat.ID | ||
|
||
media1 := &models.InputPaidMediaPhoto{ | ||
Media: "https://telegram.org/img/t_logo.png", | ||
} | ||
|
||
media2 := &models.InputPaidMediaPhoto{ | ||
Media: "attach://facebook.png", | ||
MediaAttachment: bytes.NewReader(fileDataFacebook), | ||
} | ||
|
||
media3 := &models.InputPaidMediaPhoto{ | ||
Media: "attach://youtube.png", | ||
MediaAttachment: bytes.NewReader(fileDataYoutube), | ||
} | ||
|
||
params := &bot.SendPaidMediaParams{ | ||
ChatID: chatID, | ||
StarCount: 10, | ||
Media: []models.InputPaidMedia{ | ||
media1, | ||
media2, | ||
media3, | ||
}, | ||
} | ||
|
||
_, err := b.SendPaidMedia(ctx, params) | ||
if err != nil { | ||
fmt.Printf("%+v\n", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package models | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
) | ||
|
||
type InputPaidMedia interface { | ||
inputPaidMediaTag() | ||
|
||
MarshalInputMedia() ([]byte, error) | ||
Attachment() io.Reader | ||
GetMedia() string | ||
} | ||
|
||
// InputPaidMediaPhoto https://core.telegram.org/bots/api#inputpaidmediaphoto | ||
type InputPaidMediaPhoto struct { | ||
Media string `json:"media"` | ||
|
||
MediaAttachment io.Reader `json:"-"` | ||
} | ||
|
||
func (m *InputPaidMediaPhoto) inputPaidMediaTag() {} | ||
|
||
func (m *InputPaidMediaPhoto) Attachment() io.Reader { | ||
return m.MediaAttachment | ||
} | ||
|
||
func (m *InputPaidMediaPhoto) GetMedia() string { | ||
return m.Media | ||
} | ||
|
||
func (m *InputPaidMediaPhoto) MarshalInputMedia() ([]byte, error) { | ||
ret := struct { | ||
Type string `json:"type"` | ||
*InputPaidMediaPhoto | ||
}{ | ||
Type: "photo", | ||
InputPaidMediaPhoto: m, | ||
} | ||
|
||
return json.Marshal(&ret) | ||
} | ||
|
||
// InputPaidMediaVideo https://core.telegram.org/bots/api#inputpaidmediavideo | ||
type InputPaidMediaVideo struct { | ||
Media string `json:"media"` | ||
Thumbnail InputFile `json:"thumbnail,omitempty"` | ||
Width int `json:"width,omitempty"` | ||
Height int `json:"height,omitempty"` | ||
Duration int `json:"duration,omitempty"` | ||
SupportsStreaming bool `json:"supports_streaming,omitempty"` | ||
|
||
MediaAttachment io.Reader `json:"-"` | ||
} | ||
|
||
func (m *InputPaidMediaVideo) inputPaidMediaTag() {} | ||
|
||
func (m *InputPaidMediaVideo) Attachment() io.Reader { | ||
return m.MediaAttachment | ||
} | ||
|
||
func (m *InputPaidMediaVideo) GetMedia() string { | ||
return m.Media | ||
} | ||
|
||
func (m *InputPaidMediaVideo) MarshalInputMedia() ([]byte, error) { | ||
ret := struct { | ||
Type string `json:"type"` | ||
*InputPaidMediaVideo | ||
}{ | ||
Type: "video", | ||
InputPaidMediaVideo: m, | ||
} | ||
|
||
return json.Marshal(&ret) | ||
} | ||
|
||
type PaidMediaType string | ||
|
||
const ( | ||
PaidMediaTypePreview PaidMediaType = "preview" | ||
PaidMediaTypePhoto PaidMediaType = "photo" | ||
PaidMediaTypeVideo PaidMediaType = "video" | ||
) | ||
|
||
// PaidMedia https://core.telegram.org/bots/api#paidmedia | ||
type PaidMedia struct { | ||
Type PaidMediaType | ||
|
||
Preview *PaidMediaPreview | ||
Photo *PaidMediaPhoto | ||
Video *PaidMediaVideo | ||
} | ||
|
||
func (p *PaidMedia) UnmarshalJSON(data []byte) error { | ||
v := struct { | ||
Type PaidMediaType `json:"type"` | ||
}{} | ||
err := json.Unmarshal(data, &v) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
p.Type = v.Type | ||
|
||
switch v.Type { | ||
case PaidMediaTypePreview: | ||
p.Preview = &PaidMediaPreview{} | ||
return json.Unmarshal(data, p.Preview) | ||
case PaidMediaTypePhoto: | ||
p.Photo = &PaidMediaPhoto{} | ||
return json.Unmarshal(data, p.Photo) | ||
case PaidMediaTypeVideo: | ||
p.Video = &PaidMediaVideo{} | ||
return json.Unmarshal(data, p.Video) | ||
default: | ||
return fmt.Errorf("unsupported PaidMedia type, %v", v.Type) | ||
} | ||
} | ||
|
||
// PaidMediaPreview https://core.telegram.org/bots/api#paidmediapreview | ||
type PaidMediaPreview struct { | ||
Type PaidMediaType | ||
|
||
Width int `json:"width,omitempty"` | ||
Height int `json:"height,omitempty"` | ||
Duration int `json:"duration,omitempty"` | ||
} | ||
|
||
// PaidMediaPhoto https://core.telegram.org/bots/api#paidmediaphoto | ||
type PaidMediaPhoto struct { | ||
Type PaidMediaType | ||
|
||
Photo []PhotoSize `json:"photo"` | ||
} | ||
|
||
// PaidMediaVideo https://core.telegram.org/bots/api#paidmediavideo | ||
type PaidMediaVideo struct { | ||
Type PaidMediaType | ||
|
||
Video Video `json:"video"` | ||
} | ||
|
||
// PaidMediaInfo https://core.telegram.org/bots/api#paidmediainfo | ||
type PaidMediaInfo struct { | ||
StarCount int `json:"star_count"` | ||
PaidMedia []PaidMedia `json:"paid_media"` | ||
} |
Oops, something went wrong.