const { Telegraf } = require ( 'telegraf' ) ; const Koa = require ( 'koa' ) ; const koaBody = require ( 'koa-body' ) ; const safeCompare = require ( 'safe-compare' ) ; const token = process . env . BOT_TOKEN ; if ( token === undefined ) { throw new Error ( 'BOT_TOKEN must be provided!' ) ; } const bot = new Telegraf ( token ) ; bot . command ( 'image' , ( ctx ) => ctx . replyWithPhoto ( { url : 'https://picsum.photos/200/300/?random' } ) ) ; bot . on ( 'text' , ( ctx ) => ctx . reply ( 'Hello' ) ) ; const secretPath = `/telegraf/${ bot . secretPathComponent ( ) }` ; bot . telegram . setWebhook ( `https://-----.localtunnel.me${ secretPath }` ) ; const app = new Koa ( ) ; app . use ( koaBody ( ) ) ; app . use ( async ( ctx , next ) => { if ( safeCompare ( secretPath , ctx . url ) ) { await bot . handleUpdate ( ctx . request . body ) ; ctx . status = 200 ; return ; } return next ( ) ; } ) ; app . listen ( 3000 ) ;