Telegram Send Message with Inline Keyboard
Send a message with inline keyboard buttons using Telegram Bot API in N8n Code Node.
// Send message with inline keyboard via Telegram Bot API
const botToken = $env.TELEGRAM_BOT_TOKEN;
const chatId = $input.first().json.chat_id;
const response = await fetch(
`https://api.telegram.org/bot${botToken}/sendMessage`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
chat_id: chatId,
text: "Choose an option:",
parse_mode: "HTML",
reply_markup: {
inline_keyboard: [
[
{ text: "✅ Approve", callback_data: "approve" },
{ text: "❌ Reject", callback_data: "reject" },
],
[{ text: "📋 Details", callback_data: "details" }],
],
},
}),
}
);
return [{ json: await response.json() }];