Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tahrz/simple-telegram-bot
Simple library, for create telegram bot. Only connector, interfaces and helpers nothing more, clean and simple.
https://github.com/tahrz/simple-telegram-bot
curl library php8 simple-telegram-bot telegram-bot webhook
Last synced: about 2 months ago
JSON representation
Simple library, for create telegram bot. Only connector, interfaces and helpers nothing more, clean and simple.
- Host: GitHub
- URL: https://github.com/tahrz/simple-telegram-bot
- Owner: tahrz
- License: mit
- Created: 2018-10-14T21:11:09.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2023-10-29T21:30:42.000Z (about 1 year ago)
- Last Synced: 2024-10-10T10:12:47.010Z (3 months ago)
- Topics: curl, library, php8, simple-telegram-bot, telegram-bot, webhook
- Language: PHP
- Homepage:
- Size: 30.3 KB
- Stars: 24
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple PHP telegram bot library
This library will help you, to create php telegram bot of any complexity.
> **v 2.0.0****Add library to composer:**
```
composer require tahrz/simple-telegram-bot
```**Add global variables, to config component**
```php
define('BOT_TOKEN', '');
define('BASIC_API_URL', 'https://api.telegram.org/bot' . BOT_TOKEN . '/');
define('WEBHOOK_URL', '');
```#### How to use
To create an API request, use:
```php
// create instance of ConnectionService
$connectionService = new ConnectionService();// make connection without answer
$connectionService->init('');// make connection with array answer type
$arrayResult = $connectionService->withArrayResponse('');// make connection with object anaswer type
$objectResult = $connectionService->withObjectResponse('');
```> Also, you can use `webhookConfigurationHelper`, witch build under `ConnectionService`,
> with `getWebhook`, `setWebhook` API methods. Helpers use **ONLY** `CurlConnectionService()````php
// create instance of WebhookConfigurationHelper
$webhookConfigurationHelper = new WebhookConfigurationHelper($connectionService);// get webhook info
$setWebhook = $webhookConfigurationHelper->getWebhookInfo();// set new webhook
$getWebhook = $webhookConfigurationHelper->setWebhook();// remove webhook
$removeWebhook = $webhookConfigurationHelper->removeWebhook();
```
`setWebhook()` will set a webhook on your `WEBHOOK_URL` url.> For getting Updates with or without webhook, you can use
```php
// create instance of WebhookGetUpdateHelper
$webhookUpdateHelper = new WebhookGetUpdateHelper();// create instance of GetUpdateHelper
$getUpdateHelper = new GetUpdateHelper($connectionService);// work only if you add webhook
$updatesWithWebhookAsArray = $webhookUpdateHelper->asArray();
$updatesWithWebhookAsObject = $webhookUpdateHelper->asObject();// work only without webhook
$updatesWithoutWebhook = $getUpdateHelper->asArray();
$updatesWithoutWebhook = $getUpdateHelper->asObject();
```
You always can choose, what type of data, you need to return, `array` or `object` or even **do not return you any data**.> For sending messages, you can use a `MessageHelper`
```php
// create instance of MessageHelper
$messageHelper = new MessageHelper($connectionService);// send message without response
$messageHelper->sendWithoutResponse(, '')// send message with array response type
$messageSendWithArrayResponse = $messageHelper->sendWithArrayResponse(, '')// send message with object response type
$messageSendWithObjectResponse = $messageHelper->sendWithObjectResponse(, '')