televerse_shelf 1.0.1 copy "televerse_shelf: ^1.0.1" to clipboard
televerse_shelf: ^1.0.1 copied to clipboard

Helps you build fully customizable web servers using Shelf while managing your bot's webhook on a dedicated route.

example/televerse_shelf_example.dart

import 'dart:io';

import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:televerse/televerse.dart';
import 'package:televerse_shelf/televerse_shelf.dart';

void main() async {
  // Get your token from @BotFather
  final token = Platform.environment["BOT_TOKEN"]!;

  // Take an instance of the Televerse Shelf Adapter, which we'll use
  // as the fetcher for our bot.
  final fetcher = TeleverseShelfWebhook();

  // Initialize your bot with passing the fetcher.
  final bot = Bot(
    token,
    fetcher: fetcher,
  );

  // Setup your commands, and other listeners
  bot.command('start', (ctx) async {
    await ctx.reply("Hello World!");
  });

  // Create router
  final router = Router();

  // Use the `fetcher.createHandler` to handle the incoming request to the bot.
  router.post('/webhook', fetcher.createHandler());

  // Setup other routes as usual
  router.get('/api', (req) => Response.ok("Hello from API!"));
  router.get('/health', (req) => Response.ok('{"status":"OK"}'));

  /// Add middlewares as usual :)
  final pipeline =
      Pipeline().addMiddleware(logRequests()).addHandler(router.call);

  // Start server
  final server = await serve(pipeline, 'localhost', 8080);

  // Start the bot.
  await bot.start();
  print('Server running on port ${server.port}');
}
1
likes
160
points
173
downloads

Publisher

verified publisherxooniverse.com

Weekly Downloads

Helps you build fully customizable web servers using Shelf while managing your bot's webhook on a dedicated route.

Homepage
Repository (GitHub)
View/report issues

Topics

#telegram #bot #chat #telegram-bot-api #bot-framework

Documentation

API reference

Funding

Consider supporting this project:

buymeacoffee.com
paypal.me

License

GPL-3.0 (license)

Dependencies

shelf, televerse

More

Packages that depend on televerse_shelf