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: 4 months ago
JSON representation
Simple Service to work with sending messages,photos,audios via telegram bot
- Host: GitHub
- URL: https://github.com/glebsky/simple-telegram
- Owner: Glebsky
- Created: 2021-08-20T07:01:03.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-07T09:54:13.000Z (almost 2 years ago)
- Last Synced: 2025-05-25T11:24:31.723Z (about 1 year ago)
- Topics: php, telegram, telegram-bot, telegram-bot-api, telegram-messages
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README

โ๏ธ ๐ ๐ผ๏ธ ๐ง => ๐ค => ๐
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
```