-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
single-factor-auth-web/sfa-web-ton-telegram-example/server/api/telegram.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; |
181 changes: 172 additions & 9 deletions
181
single-factor-auth-web/sfa-web-ton-telegram-example/server/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters