telegram-bot-sdk / standalone-starter
Telegram Bot SDK Standalone Starter Project
Installs: 50
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Open Issues: 0
Type:project
Requires
- php: >=8.1
- phpoption/phpoption: ^1.7
- telegram-bot-sdk/telegram-bot-sdk: ^4.0@dev
- vlucas/phpdotenv: ^5.2
This package is auto-updated.
Last update: 2024-10-08 05:07:21 UTC
README
Standalone starter for Telegram Bot SDK to create Telegram Bots in PHP.
Features
- Multi-Bots.
- Webhook.
- Updates Polling.
- Commands.
- Event Listener.
Usage
composer create-project telegram-bot-sdk/standalone-starter mybot
- Create a bot with Botfather.
- Open
.env
and configure your token and domain (Copy.env.example
if you have cloned this project). - Explore
config/telegram.php
- Follow docs.
- Build bots!
Helpers
The starter comes with some useful helpers for convenience that can be found in bot/helpers.php
.
telegram()
- Get an instance of BotManager from the container.
Directory Structure
.
├── .env - Project environment variable.
├── bootstrap - Bot bootstrapping files.
├── bot - Your bot main files.
│ ├── Commands - Bot commands.
│ ├── Console - CLI console commands.
│ ├── Facades - Bot Facades.
│ ├── Http - Bot controllers.
│ └── Listeners - Event Listeners.
├── config - Config files.
| └── telegram.php - Your main SDK configuration.
└── public - Public facing files.
└── index.php - Project index file.
└── pooling.php - Long-pooling update handler.
└── webhook.php - Webhook update handler.
Webhook Setup
IMPORTANT: Telegram requires your domain to have an SSL certificate (https) to setup a webhook.
Open .env
and fill your domain:
TELEGRAM_WEBHOOK_DOMAIN=www.yourdomain.com
The standalone starter comes with a CLI helper to setup webhook for your bot. Simply fire the below command.
php telegram webhook:setup <botname>
This will setup your bot's webhook to this URL:
https://<www.yourdomain.com>/webhook.php?token=YourBotToken&bot=YourBotName
The webhook file will verify any inbound requests to make sure its a valid request from Telegram. It'll deny any other requests. So you need not have to worry.
You can process inbound updates either using an event listener or directly in the given bot/Http/WebhookController.php
in listenForUpdate()
method.
License
This project is released under the BSD 3-Clause License.