Telegraf.js: "Bad Request: wrong file identifier/HTTP URL specified" when trying to send a video with Context.replyWithVideo()

Viewed 44

I'm trying to make a TikTok downloader bot for Telegram but, even if the link is correct, Telegraf gives an error: Bad Request: wrong file identifier/HTTP URL specified.

This is the code I'm currently using to do this:

import {Telegraf} from "telegraf"
import {config as DotEnvConfig} from "dotenv"
import axios from 'axios'

const API_URL = "https://www.tikwm.com/api/"
const TIKWM = "https://www.tikwm.com"
async function downloadTiktokVideo(url: string) {
    let res = await axios.post(API_URL, null, {
        params: {
            url: url,
            count: 12,
            cursor: 0,
            web: 1,
            hd: 1
        }
    })
    return {
        nowm: TIKWM + res.data.data.play,
        music: TIKWM + res.data.data.music
    }
}

const client = new Telegraf(process.env.TOKEN!)

const regexes = [
    "(\\S+tiktok.com\\/@[a-zA-Z]{2,24}\\/video\\/[0-9]{19}\\S+)",
    "(\\S+vm.tiktok.com\/[a-zA-Z1-9]{9}\/)"
];

client.on('text', async(ctx) => {
    if(ctx.message.text) {
        for(const regex of regexes) {
            if(ctx.message.text.match(regex)) {
                const url = ctx.message.text.match(regex)![0]
                const video = await downloadTiktokVideo(url.toString())
                ctx.replyWithVideo(video.nowm);
            }
        }
    }
})

and this is the error stack btw:

C:\Users\Antogamer\Desktop\TikTokDownloader\node_modules\telegraf\lib\core\network\client.js:291
            throw new error_1.default(data, { method, payload });
                  ^

TelegramError: 400: Bad Request: wrong file identifier/HTTP URL specified
    at Telegram.callApi (C:\Users\Antogamer\Desktop\TikTokDownloader\node_modules\telegraf\lib\core\network\client.js:291:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  response: {
    ok: false,
    error_code: 400,
    description: 'Bad Request: wrong file identifier/HTTP URL specified'
  },
  on: {
    method: 'sendVideo',
    payload: {
      chat_id: censoredchatid,
      video: 'https://www.tikwm.com/video/media/play/7141851362043628842.mp4'
    }
  }
}

client.launch()

for a video link, just get a random video from TikTok.

UPDATE: Fixed, I just downloaded the video and sent it.

0 Answers
Related