Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/glebsky/simple-telegram

Simple Service to work with sending messages,photos,audios via telegram bot
https://github.com/glebsky/simple-telegram

php telegram telegram-bot telegram-bot-api telegram-messages

Last synced: 27 days ago
JSON representation

Simple Service to work with sending messages,photos,audios via telegram bot

Awesome Lists containing this project

README

        

![logo](https://i.ibb.co/Vv58qTS/simple-Telegram.png "Simple Telegram")


Latest Stable Version
Total Downloads
PHP

StyleCI


βœ‰οΈ πŸ“„ πŸ–ΌοΈ 🎧 => πŸ€– => 😊



A simple way to send messages to the user through the telegram bot.

---


[
Telegram Bot Documentation |
Supported formats
]

## About
This is a simple class that will allow you to easily send messages, documents, photos, audio to users. The library is specially designed to have fewer dependencies.

## Installation
The library can be installed using the composer:
```bash
сomposer install glebsky/simple-telegram
```
Or you can take a ready-made class from the `src` folder since there are no dependencies.
## How to use
Add in use section:
```php
use Glebsky\SimpleTelegram\SimpleTelegram;
```
And add your SimpleTelegram To your code section to send messages:
```php
$botTokent = '132312455234:DSQWDQWQWEZCZXKGWETJHSOASDZXC_s';
$chat_id = '123456789';
$telegram = new SimpleTelegram($botTokent,$chat_id);

$telegram->sendMessage('Test Message');
$telegram->sendDocument(__DIR__.'/demo.txt','Document Caption');
$telegram->sendPhoto(__DIR__.'/photo.jpg','Photo Caption');
$telegram->sendAudio(__DIR__.'/audio.mp3','Audio Caption');
```
>Please note that the path to the file must be specified absolute.

You can change the addressee or get the current addressee (chat_id)
```php
$telegram->setRecipient('123456789');
$telegram->getRecipient(); // 123456789
```
Also, you can choose not to specify the receiver when initializing the class; this can be done later before sending.
```php
$botTokent = '132312455234:DSQWDQWQWEZCZXKGWETJHSOASDZXC_s';
$telegram = new SimpleTelegram($botTokent);

$chat_id = '123456789';
$telegram->setRecipient($chat_id);

$telegram->sendMessage('Test Message');
```
Or you can combine queries
```php
$telegram = new SimpleTelegram($botTokent);

$chat_id = '123456789';
$telegram->setRecipient($chat_id)->sendPhoto(__DIR__.'/photo.jpg','Photo Caption');
```

Submission methods return `true` on successful submission and `false` on failure

```php
$telegram->sendMessage('Test Message'); // true or false
$telegram->sendDocument(__DIR__.'/demo.txt','Document Caption'); // true or false
$telegram->sendPhoto(__DIR__.'/photo.jpg','Photo Caption'); // true or false
$telegram->sendAudio(__DIR__.'/audio.mp3','Audio Caption'); // true or false
```