This is a lightweight starter kit for building Telegram bots using the Nutgram PHP framework.
- Nutgram Framework: High-performance Telegram Bot framework.
- Environment Configuration: Easy management of environment variables with
phpdotenv. - Caching: PSR-16 cache support out of the box.
- Testing: Ready-to-use testing environment with Pest.
- Structured: Organized directory structure for Commands and Conversations.
- PHP 8.2 or higher
- Composer
-
Create the project:
composer create-project nutgram/starter-kit my-telegram-bot cd my-telegram-bot -
Install dependencies:
composer install
-
Configure the environment: Copy the example environment file and add your Telegram Bot token:
cp .env.example .env
Edit
.envand set yourTOKEN:TOKEN=your_telegram_bot_token_here WEBHOOK_TOKEN=random_webhook_token
To run the bot in polling mode (ideal for development), execute:
php bot.phpTo use the webhook mode, point your web server's document root to the public/ directory. Ensure your server is accessible via HTTPS.
Finally, you need to register your webhook URL with Telegram. You can do this by making an HTTP request (e.g., using curl) to the following address:
curl "https://api.telegram.org/botTOKEN/setWebhook?secret_token=WEBHOOK_TOKEN&url=https://YOUR_DOMAIN"Replace:
TOKENwith the same value you used in your.envfilehttps://YOUR_DOMAINwith your actual webhook URL.WEBHOOK_TOKENwith the same value you used in your.envfile
src/routes.php: Register your commands, conversations, and handlers.src/bootstrap.php: Bot initialization and configuration.public/index.php: Entry point for both polling and webhook.tests/: Feature and unit tests.
You can run the tests using Pest:
composer testThis project is open-sourced software licensed under the MIT license.