baks-dev/manufacture-part-telegram
Installation
composer require baks-dev/manufacture-part-telegram
php bin/console baks:assets:install
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case
.env:
TELEGRAM_BOT_TOKEN=your_bot_token_here
/start, /create_part).Where to Look First
config/manufacture-part-telegram.php (if auto-generated by baks:assets:install).app/Console/Commands/ for custom workflows.TelegramUpdateHandler or similar in app/Http/Controllers/ or src/.app/Entities/ or src/Entity/ for Part, ProductionBatch, etc.Telegram Bot Integration
Symfony\Component\HttpKernel\EventListener\TerminateEventListener or similar).// In a controller or command
$telegram = app(\BaksDev\ManufacturePartTelegram\Telegram\TelegramClient::class);
$response = $telegram->sendMessage(
chatId: $userId,
text: "Production batch created: #{$batch->id}"
);
Production Batch Creation
/create_part).$batch = app(\BaksDev\ManufacturePartTelegram\Entity\ProductionBatch::class);
$batch->productId = $productId;
$batch->quantity = $quantity;
$batch->userId = $userId; // Telegram user ID
$entityManager->persist($batch);
$entityManager->flush();
State Management
pending, in_production, completed).$batch->changeStateTo(\BaksDev\ManufacturePartTelegram\Entity\ProductionBatch::STATE_IN_PRODUCTION);
Webhook Setup
routes/web.php or routes/telegram.php):
Route::post('/telegram/webhook', [TelegramUpdateHandler::class, 'handle']);
$telegram->setWebhook(['url' => url('/telegram/webhook')]);
Event-Driven Extensions
BatchCreated, BatchCompleted) to trigger notifications or side effects:
// In EventSubscriber
public function onBatchCreated(BatchCreatedEvent $event): void {
$this->telegram->sendMessage(
chatId: $event->getUserId(),
text: "Batch {$event->getBatch()->id} is ready!"
);
}
Database Schema Mismatches
doctrine:migrations:diff and migrate after updating the package or manually modifying migrations.state) if extending the ProductionBatch entity.Telegram API Rate Limits
dispatch(new SendTelegramMessage($userId, $message))->onQueue('telegram');
User ID Handling
telegram_user_id in a pivot table or user extension).$user->telegramUserId = $telegramUpdate->getMessage()->getFrom()->getId();
Local Development Quirks
ngrok to expose your local server for Telegram webhook testing:
ngrok http 8000
ngrok.io endpoint.Translation Issues
resources/lang/ or extend the language provider.Log Telegram Updates Add a middleware to log raw updates for debugging:
// app/Http/Middleware/LogTelegramUpdates.php
public function handle($request, Closure $next) {
if ($request->is('telegram/webhook')) {
\Log::debug('Telegram Update:', $request->all());
}
return $next($request);
}
Test with BotFather Use Telegram’s Test Bot to simulate updates locally.
Check for Deprecated Methods
The package is new (2026). Verify if methods like sendMessage() have changed in newer Telegram Bot API versions.
Custom Commands Extend the bot’s command handler to add new Telegram commands:
// app/Telegram/Commands/CreatePartCommand.php
public function handle(TelegramContext $context) {
$args = $context->getArgs();
// Parse $args[0] as product ID, $args[1] as quantity
// Create batch and reply
}
Hook into Production Workflows Subscribe to events or override services:
// config/services.php
'manufacture_part_telegram.production_workflow' => [
'class' => \App\Services\CustomProductionWorkflow::class,
];
Add Notifications
Extend the ProductionBatch entity to include notification logic:
// app/Entities/ProductionBatch.php
public function markAsCompleted(): void {
$this->state = self::STATE_COMPLETED;
// Trigger email/SMS/Telegram notifications
event(new BatchCompleted($this));
}
Localization
Override the package’s language files in resources/lang/{locale}/manufacture-part-telegram.php.
Testing
Use the --group=manufacture-part-telegram flag to run isolated tests:
php bin/phpunit --group=manufacture-part-telegram
Mock Telegram updates in tests:
$update = new \BaksDev\ManufacturePartTelegram\Telegram\Update\MessageUpdate(
new \BaksDev\ManufacturePartTelegram\Telegram\User(123),
new \BaksDev\ManufacturePartTelegram\Telegram\Message('test', '/create_part')
);
$handler = new TelegramUpdateHandler();
$handler->handle($update);
How can I help you explore Laravel packages today?