generated from NEARBuilders/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
93fb718
commit fe3a4f6
Showing
8 changed files
with
181 additions
and
18 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ yarn-error.log* | |
|
||
# local env files | ||
.env*.local | ||
.env | ||
|
||
# vercel | ||
.vercel | ||
|
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,55 @@ | ||
import type { VercelRequest, VercelResponse } from '@vercel/node'; | ||
|
||
export default async function handler( | ||
req: VercelRequest, | ||
res: VercelResponse | ||
) { | ||
if (req.method !== 'POST') { | ||
return res.status(405).json({ message: 'Method not allowed' }); | ||
} | ||
|
||
try { | ||
const { projectName, description, timeline, customTimeline, contact } = req.body; | ||
|
||
// Validate required fields | ||
if (!projectName || !description || !contact || !(timeline || customTimeline)) { | ||
return res.status(400).json({ message: 'Missing required fields' }); | ||
} | ||
|
||
// Format message for Telegram | ||
const message = ` | ||
🚀 New Project Request | ||
📋 Project Name: ${projectName} | ||
📝 Description: ${description} | ||
⏰ Timeline: ${timeline === 'custom' ? customTimeline : timeline} | ||
📧 Contact: ${contact} | ||
`; | ||
|
||
// Send to Telegram | ||
const response = await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
chat_id: process.env.TELEGRAM_CHANNEL_ID, | ||
text: message, | ||
parse_mode: 'HTML', | ||
}), | ||
}); | ||
|
||
if (!response.ok) { | ||
const error = await response.json(); | ||
throw new Error(error.description || 'Failed to send message to Telegram'); | ||
} | ||
|
||
return res.status(200).json({ message: 'Project request sent successfully' }); | ||
} catch (error) { | ||
console.error('Error sending to Telegram:', error); | ||
return res.status(500).json({ message: 'Error sending project request' }); | ||
} | ||
} |
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
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
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
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
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,9 @@ | ||
{ | ||
"version": 2, | ||
"functions": { | ||
"api/send-telegram.ts": { | ||
"memory": 1024, | ||
"maxDuration": 10 | ||
} | ||
} | ||
} |