glebsky/simple-telegram

Just a Simple Telegram class that can help you to send Messages and Files via Telegram Bot

1.0.0 2021-08-21 08:17 UTC

This package is auto-updated.

Last update: 2024-04-27 00:13:14 UTC


README

logo Latest Stable Version Total Downloads Latest Unstable Version License PHP CodeFactor 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:

с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:

use Glebsky\SimpleTelegram\SimpleTelegram;

And add your SimpleTelegram To your code section to send messages:

$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)

$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.

$botTokent = '132312455234:DSQWDQWQWEZCZXKGWETJHSOASDZXC_s';
$telegram = new SimpleTelegram($botTokent);

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

$telegram->sendMessage('Test Message');

Or you can combine queries

$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

$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