繁体   English   中英

如何在电报机器人中从用户那里下载音频消息?

[英]How to download an audio message from a user in a telegram bot?

一天中的昂贵时间。 有一个问题。 我想制作一个能够读取用户语音消息并将其下载到服务器的电报机器人。 问题是,如何让机器人自动理解音频被发送到它并保存到指定目录? PS试过了

bot.on('voice', (msg)=>{
        bot.getFile(msg.voice.file_id, () => {
            bot.getFile(voiceId).then((resp) => {
                {
                    file_id = 'file_id',
                        file_size = 6666,
                    file_path = 'file_path'
                }
                bot.getFileLink(voiceId).then((resp) => {
                    'https://api.telegram.org/file/bot<BOT_TOKEN>/<file_path>'
                });
            });
        });

但文件只下载了我指定的 id 和路径

您可以使用axiostelegram.getFileLink() :(这是一个电报示例)

bot.on("voice",ctx => {
  ctx.telegram.getFileLink(ctx.message.vioce.file_id).then((url) => {
      axios.get(url, { responseType: "arraybuffer" }).then((voice) => {
      fs.writefile(`./lib/voices/${ctx.from.id}/${ctx.message.vioce.file_id}.ogg`,voice)})
  })
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM