Skip to content

Commit

Permalink
Add Telegram webhook endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ihsraham committed Oct 28, 2024
1 parent 94da78e commit 4ebf459
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Telegraf } from "telegraf";

export default async function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method not allowed' });
}

const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN);

// Command handler
bot.command('start', async (ctx) => {
try {
await ctx.reply('Welcome to Web3 Wallet! Click below to get started:', {
reply_markup: {
inline_keyboard: [[
{
text: "Open Web3 Wallet 🚀",
web_app: { url: process.env.APP_URL }
}
]]
}
});
} catch (error) {
console.error('Error in start command:', error);
}
});

try {
// Process the update
await bot.handleUpdate(req.body);
res.status(200).json({ ok: true });
} catch (error) {
console.error('Webhook handling error:', error);
res.status(500).json({ error: 'Failed to process update' });
}
}

// Disable body parsing as Telegram sends updates in raw format
export const config = {
api: {
bodyParser: false,
},
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"express": "^4.19.2",
"express-rate-limit": "^7.4.0",
"express-session": "^1.18.0",
"jsonwebtoken": "^8.5.1"
"jsonwebtoken": "^8.5.1",
"telegraf": "^4.16.3"
},
"description": "",
"keywords": [],
Expand Down

0 comments on commit 4ebf459

Please sign in to comment.