Skip to content

Commit 7ad6c2b

Browse files
committed
Added Documentation
1 parent e08b1b5 commit 7ad6c2b

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<div align="center">
2+
<img align="center" src="https://github.com/TelegramSDK/BotAPI/assets/115643607/7d440cea-b563-49ce-b137-1144949d9636" alt="Telegram Logo" style="margin-bottom:20px;">
3+
<h1>TelegramSDK - BotAPI</h1>
4+
</div>
5+
6+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/telegramsdk/botapi.svg?label=composer&logo=composer)](https://packagist.org/packages/telegramsdk/botapi) ![PHP](https://img.shields.io/packagist/dependency-v/telegramsdk/botapi/php?logo=php)
7+
8+
9+
10+
## 🛠 Instalation
11+
You can install the package via composer:
12+
13+
```bash
14+
composer require telegramsdk/botapi
15+
```
16+
17+
## ❔ Usage
18+
* Full documentation can be found [here](https://github.com/TelegramSDK/BotAPI/tree/main/docs).
19+
* Examples can be found [here](https://github.com/TelegramSDK/BotAPI/tree/main/examples).
20+
21+
## 📝 Testing
22+
Run Unit tests:
23+
```bash
24+
composer test
25+
```
26+
Before running tests make sure you have `runkit7` installed:
27+
```bash
28+
composer runkit
29+
```
30+
31+
32+
## ⚖️ License
33+
This project is under the [MIT License](https://github.com/TelegramSDK/BotAPI/blob/main/LICENSE).

docs/00-introduction.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Getting Started
2+
Before reading this documentation I recommend having a look at [Telegram Docs](https://core.telegram.org/bots/api).
3+
4+
If you haven't installed this library yet, install it via composer:
5+
```bash
6+
composer require telegramsdk/botapi
7+
```
8+
9+
## General Information
10+
The library provides one main class: `TelegramSDK\BotAPI\Telegram\Bot`.<br>
11+
You can use it to send requests to Telegram or get the updates.
12+
13+
```php
14+
<?php
15+
16+
use TelegramSDK\BotAPI\Telegram\Bot;
17+
18+
$bot = new Bot("YOUR_BOT_TOKEN"); // Your bot token
19+
20+
$bot->sendMessage([ // Send a message
21+
"chat_id" => 123 // Your chat id
22+
"text" => "A message"
23+
]);
24+
```
25+
26+
### How does it work?
27+
Every method in the `Bot` class is from the [Telegram Api](https://core.telegram.org/bots/api#available-methods) and it's case insensitive.
28+
29+
## Examples
30+
You can see the available examples [here](https://github.com/TelegramSDK/BotAPI/tree/main/examples).

docs/01-updates.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Getting Updates
2+
As mentioned in the introduction, the `Bot` class provides a method to get updates.
3+
4+
There are 3 updates methods:
5+
* `Bot::NO_UPDATES`: No updates are expected from Telegram, is set to default.
6+
* `Bot::UPDATES_FROM_GET_UPDATES`: Get updates from the `getUpdates()` method.
7+
* `Bot::UPDATES_FROM_WEBHOOK`: Get updates from [`php://input`](https://www.php.net/manual/en/wrappers.php.php#wrappers.php.input).
8+
9+
## How to use them
10+
```php
11+
<?php
12+
13+
use TelegramSDK\BotAPI\Telegram\Bot;
14+
15+
// With getUpdates()
16+
$bot1 = new Bot("YOUR_BOT_TOKEN", Bot::UPDATES_FROM_GET_UPDATES);
17+
18+
$updates = $bot1->updates();
19+
foreach($updates->result as $update){
20+
echo json_encode($update) . "\n";
21+
}
22+
23+
24+
// With a webhook
25+
$bot2 = new Bot("YOUR_BOT_TOKEN", Bot::UPDATES_FROM_WEBHOOK);
26+
27+
$update = $bot2->updates();
28+
echo (json_encode($update) ?? "No updates found.") . "\n";
29+
```

0 commit comments

Comments
 (0)