televerse_shelf
extends the functionality of the Televerse framework, enabling you to integrate the power of Shelf into your Telegram bots. While Televerse natively supports webhooks, it implicitly handles server creation, limiting user control over routes and server customization. With televerse_shelf
, you can build fully customizable web servers using Shelf while managing your bot's webhook on a dedicated route.
This package is perfect for developers who want to combine the simplicity of Televerse with the flexibility of Shelf to handle other web server tasks alongside Telegram bot updates.
-
Customizable Webhook Routes
Define a specific route for handling Telegram updates via webhooks, without interfering with other routes. -
Full Shelf Integration
Seamlessly use Shelf's powerful routing and middleware alongside Televerse. -
Dedicated TeleverseShelfWebhook
A custom adapter for Televerse, enabling webhook updates via Shelf. -
Multi-route Support
Dedicate a single port for your bot webhook and additional routes, like APIs or health checks, all under one server.
Add televerse_shelf
to your pubspec.yaml
:
dependencies:
televerse_shelf: <latest>
Then import the package in your Dart code:
import 'package:televerse_shelf/televerse_shelf.dart';
Here's a basic example to get you started with televerse_shelf
:
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 {
final token = Platform.environment['BOT_TOKEN']!;
final fetcher = TeleverseShelfWebhook();
final bot = Bot(token, fetcher: fetcher);
bot.command('start', (ctx) async {
await ctx.reply('Hello, world!');
});
final router = Router();
// Set up your webhook route
router.post('/webhook', fetcher.createHandler());
// Define other custom routes
router.get('/api', (req) => Response.ok('Hello from API!'));
router.get('/health', (req) => Response.ok('{"status":"OK"}'));
final pipeline = Pipeline().addMiddleware(logRequests()).addHandler(router.call);
final server = await serve(pipeline, 'localhost', 8080);
await bot.start();
print('Server running on port ${server.port}');
}
TeleverseShelfWebhook
: Manages webhook updates and integrates with Shelf.- Custom Routes: Use Shelf's
Router
to define/api
and/health
alongside the bot's/webhook
. - Pipeline & Middleware: Add logging, authentication, or other middleware to your server.
To use televerse_shelf
effectively:
- Set Up Webhooks: Use
TeleverseShelfWebhook
andfetcher.createHandler()
for handling webhook routes. - Customize Your Server: Combine Televerse with Shelf’s routing and middleware to create versatile applications.
- Run Your Bot: Call
bot.start()
to initiate the bot alongside your server.
For detailed examples and advanced usage, check out the Televerse documentation.
- Deploy bots on a single port with APIs or health checks.
- Build server applications that combine bot updates with REST APIs.
- Add middleware for logging, rate-limiting, or security to your bot server.
We’d love to see contributions from the community! Feel free to fork the repository, open issues, or submit pull requests.
If you find televerse_shelf
helpful, consider giving us a star on our GitHub repository. It motivates us to keep building cool tools!
Need help? Have ideas? Join the discussion with other developers:
Thank you for using televerse_shelf
! 🚀