Skip to content

How can I access mp3 or wav file of voice message sended? #1800

Answered by MKRhere
lofti198 asked this question in Q&A
Discussion options

You must be logged in to vote

Example:

import { message } from "telegraf/filters";

bot.on(message("audio"), async ctx => {
	const link = await ctx.telegram.getFileLink(ctx.message.audio.file_id);

	// link.href is the link to fetch audio from
	// use any http client like fetch / axios / ... to fetch the file
	const res = await axios(link.href);
	// write audio file to disk
	fs.writeFileSync("filename.mp3", res.data);
});

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by lofti198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants