import * as Sentry from '@sentry/node' ; import { NowRequest , NowResponse } from '@vercel/node' ; import handleListenCommands from '../_utils/telegram/commands' ; import handleListenEvents from '../_utils/telegram/events' ; const { NODE_ENV , SENTRY_DSN , TELEGRAM_BOT_TOKEN } = process . env ; Sentry . init ( { dsn : SENTRY_DSN } ) ; export default async ( request , response ) : Promise < void > => { try { if ( request . query . token === TELEGRAM_BOT_TOKEN ) { const { message } = request . body ; await handleListenEvents ( message ) ; await handleListenCommands ( message ) ; response . status ( 200 ) . send ( 'ok' ) ; } else { response . status ( 401 ) . send ( 'Unauthorized' ) ; } } catch ( error ) { if ( NODE_ENV === 'development' ) { console . error ( error ) ; } else { Sentry . captureException ( error ) ; } response . status ( 200 ) . send ( 'ok' ) ; } } ;