Giter Site home page Giter Site logo

sollidy / telegram-bot-vercel-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
65.0 0.0 66.0 55 KB

📦 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

TypeScript 100.00%
telegraf telegram-bot vercel vercel-deployment vercel-serverless boilerplate-template nodejs

telegram-bot-vercel-boilerplate's Issues

How to add more API endpoints

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.

/api: 404 not found.

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.

Deployed successfully but bot is not responding

Hi, I forked this project and deployed it to Vercel (BOT_TOKEN env is added) and it was a success. The bot, on the other hand, is not responding. Is there any additional step I need to add to my vercel config?

Screenshot 2023-11-26 at 8 41 35 PM

local dev works, though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.