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
Binary file added examples/send_video/examle_video.mp4
Binary file not shown.
48 changes: 48 additions & 0 deletions examples/send_video/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"bytes"
"context"
"fmt"
"os"
"os/signal"

"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
)

// Send any text message to the bot after the bot has been started

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)
}

func handler(ctx context.Context, b *bot.Bot, update *models.Update) {
fileData, errReadFile := os.ReadFile("./examples/send_video/examle_video.mp4")
if errReadFile != nil {
fmt.Printf("error read file, %v\n", errReadFile)
return
}

params := &bot.SendVideoParams{
ChatID: update.Message.Chat.ID,
Video: &models.InputFileUpload{Filename: "examle_video.mp4", Data: bytes.NewReader(fileData)},
Caption: "New uploaded example video",
}

b.SendVideo(ctx, params)
}