-
Notifications
You must be signed in to change notification settings - Fork 5
/
webhook.js
96 lines (79 loc) · 2.67 KB
/
webhook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const express = require('express');
const axios = require('axios');
const router = express.Router();
require('dotenv').config();
const BOT_TOKEN = process.env.BOT_TOKEN;
const TELEGRAM_API_URL = `https://api.telegram.org/bot${BOT_TOKEN}`;
const WEBHOOK_URL = `${process.env.WEBHOOK_URL}/webhook`; // Replace with your actual webhook URL
router.post('/', async (req, res) => {
console.log('Received webhook');
const { message } = req.body;
if (message && message.text && message.text === '/start') {
const chatId = message.chat.id;
const replyMarkup = {
inline_keyboard: [[
{
text: 'OPEN APP 🚀',
web_app: {
url: process.env.WEB_APP_URL
}
}
]]
};
try {
const response = await axios.post(`${TELEGRAM_API_URL}/sendMessage`, {
chat_id: chatId,
text: `
🪄 *Welcome to Account Abstraction Magic!* 🪄
✨ *A seamless experience for Telegram users!*
💼 *Custodial Wallet:*
Created at first use, securely stored in Azure Key Vault.
🔑 *Smart Accounts:*
Auto-creation using Biconomy's AA.
⚡️ *Mint NFTs:*
Tap the mint button to use your smart account.
💸 *No Gas Fees:*
Biconomy Paymaster covers them!
🔄 *Transfer NFTs:*
Withdraw and transfer your NFTs easily.
🌐 *View on OpenSea:*
Check out your NFTs on OpenSea.
⚡️ *Deployed on Base:*
Fast, cheap transactions.
📲 *Your NFTs:*
Displayed directly in the app.
👉 Click the button below to open app!
`,
reply_markup: replyMarkup,
parse_mode: "Markdown"
});
if (response.data.ok) {
console.log('Message sent successfully');
res.status(200).send('Message sent');
} else {
console.log('Failed to send message:', response.data);
res.status(500).send('Failed to send message');
}
} catch (error) {
console.error('Error sending message:', error);
res.status(500).send('Error sending message');
}
} else {
res.status(200).send('Not a /start command');
}
});
async function setWebhook() {
try {
const response = await axios.post(`${TELEGRAM_API_URL}/setWebhook`, {
url: WEBHOOK_URL
});
if (response.data.ok) {
console.log('Webhook set successfully');
} else {
console.log('Failed to set webhook:', response.data);
}
} catch (error) {
console.error('Error setting webhook:', error);
}
}
module.exports = { router, setWebhook };