欢迎光临
我们一直在努力

使用 Go-Telegram-Bot-Api 向TG机器人发送文件并获取直链

package main

import (
	"fmt"
	"log"

	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)

func main() {
	bot, err := tgbotapi.NewBotAPI("token")
	if err != nil {
		log.Panic(err)
	}

	bot.Debug = false

	log.Printf("Authorized on account %s", bot.Self.UserName)

	updateConfig := tgbotapi.NewUpdate(0)

	// Tell Telegram we should wait up to 30 seconds on each request for an
	// update. This way we can get information just as quickly as making many
	// frequent requests without having to send nearly as many.
	updateConfig.Timeout = 60

	// Start polling Telegram for updates.


	// Let's go through each update that we're getting from Telegram.
	for update := range updates {

		if update.Message == nil { // ignore any non-Message updates
			continue
		}

		if !update.Message.IsCommand() { // ignore any non-command Messages
			continue
		}
		msg := tgbotapi.NewMessage(update.Message.Chat.ID, "")
		switch update.Message.Command() {
		case "upload":
			file := tgbotapi.FilePath("1.mp4")
			msg2 := tgbotapi.NewVideo(update.Message.Chat.ID, file)
			sendmsg, err := bot.Send(msg2)
			if err != nil {
				log.Panic(err)
			}
			url, _ := bot.GetFileDirectURL(sendmsg.Video.FileID)
			fmt.Println(url)//打印出直链
		default:
			msg.Text = "I don't know that command"
		}


	}
}
当向机器人发送/upload命令后就会开始上传
 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载:家里蹲的狐狸 » 使用 Go-Telegram-Bot-Api 向TG机器人发送文件并获取直链

分享到: 生成海报
avatar

热门文章

  • 评论 抢沙发

    • QQ号
    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址

    登录

    忘记密码 ?

    切换登录

    注册

    我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活