-
Notifications
You must be signed in to change notification settings - Fork 173
Composer basics
Composer is a kind-of package manager that installs packages should you need them.
It is the default repository of Composer.
Please check https://getcomposer.org/ for more information on that. The authors of composer should have a pretty decent how-to, way better than what I could write.
A basic example to install the Telegram API would be to create a new project. Then, require the package and finally execute the install.
mkdir ~/myProject
cd ~/myProject
composer.phar require unreal4u/telegram-api:~2.4
This will install the PHP 7 Telegram Bot API with all its dependencies within a vendor folder. To be able to use it, create an example.php file with the following:
<?php
declare(strict_types = 1);
include 'vendor/autoload.php';
use GuzzleHttp\Exception\ClientException;
use unreal4u\TelegramAPI\TgLog;
use unreal4u\TelegramAPI\Telegram\Methods\GetMe;
$tgLog = new TgLog(BOT_TOKEN);
$getMe = new GetMe();
try {
$response = $tgLog->performApiRequest($getMe);
echo '<pre>';
var_dump($response);
echo '</pre>';
} catch (ClientException $e) {
// Do whatever you want, function below contains exact JSON output from Telegram
echo 'Exception catched, error is: <pre>';
print_r(json_decode((string)$e->getResponse()->getBody()));
echo '</pre>';
}
Don't forget to define the constant BOT_TOKEN with your actual token.
If you get some information back, congratulations! You are ready to use this package as you please.