sollidy / telegram-bot-vercel-boilerplate Goto Github PK
View Code? Open in Web Editor NEW📦 Telegram Bot Starter kit based on Node.js and Telegraf for deploying on Vercel.
Home Page: https://t.me/Node_api_m_bot
License: MIT License
📦 Telegram Bot Starter kit based on Node.js and Telegraf for deploying on Vercel.
Home Page: https://t.me/Node_api_m_bot
License: MIT License
Hi, I would like to know how can I add more endpoints, for example when visiting api/hello, I would like to automate something, for example call to greeting command.
I tried this:
import express, { Request, Response } from 'express'
import { startVercel } from '../src'
import { whey, casein } from '../src/scraper/scraper'
import { sendMessage, sendError } from '../src/scraper/telegram'
import { Product } from '../src/interfaces'
import { manage, insert, update } from '../src/scraper/postgres'
import { VercelRequest, VercelResponse } from '@vercel/node'
const app = express()
// enable JSON body parser
app.use(express.json())
// Handle requests to the root URL to check if the server is running
app.get('/', (req: Request, res: Response) => {
res.send('<h1>Server is running!</h1>')
})
// Handle requests to the root URL for Vercel function and other routes
app.all('*', async (req: Request | VercelRequest, res: Response | VercelResponse, next: Function) => {
try {
if ((req as VercelRequest).query !== undefined) {
// If it's a Vercel request, handle it using the startVercel function
await startVercel(req as VercelRequest, res as VercelResponse)
} else {
// If it's not a Vercel request, continue to the next middleware
next()
}
} catch (e: any) {
res.status(500).send('<h1>Server Error</h1><p>Sorry, there was a problem</p>')
console.error(e.message)
}
})
// Handle requests to /evowhey endpoint
app.get('/evowhey', async (req: Request, res: Response) => {
try {
const product: Product = await whey()
const message = `*HSN |* [${product.product}](${product.link}) *| ${product.price.replace('.', ',')}€*`
await manage(product).then(async result => {
if (result.rows.length === 0) {
await insert(product).then(() => {
void sendMessage(message)
}).catch((error: string) => {
console.log(error)
void sendError(error)
})
} else {
product.price = '26.10'
await update(product).then((result) => {
console.log(result)
const updatedMessage = `*HSN |* [${product.product}](${product.link}) *|* ${result.originalPrice} *➜ ${product.price.replace('.', ',')}€*${result.message}`
void sendMessage(updatedMessage)
}).catch((error: string) => {
console.log(error)
void sendError(error)
})
}
})
res.send(product)
} catch (error) {
console.error('Error fetching Evowhey:', error)
res.status(500).send('Error fetching Evowhey')
}
})
// Handle requests to /casein endpoint
app.get('/casein', async (req: Request, res: Response) => {
try {
const result = await casein()
res.send(result)
} catch (error) {
console.error('Error fetching Casein:', error)
res.status(500).send('Error fetching Casein')
}
})
export default app
But its not working, I dont know if maybe I have to add something to vercel.json or any other file.
Thanks.
I forked your repo and imported to Vercel, added BOT_TOKEN variables within double quotes "", deployed and it doesn't work!
/api
500
production
404: Not Found
I know for a fact that the code is alright, it is just that i am messing up somewhere. I am not familiar with Vercel so can't really fix it and I haven't found any solution elsewhere on the Internet too. I will highly appreciate your help!
P.S. i tried deploying on different Vercel projects with different Bot Tokens several times with tweaks here and there like promote to production, added VERCEL_URL manually, changed Deployment Protection and couple of more things.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.