Skip to content

paranoiasystem/TelegramBot-PHP-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TelegramBot-PHP-library

Travis Packagist Total Downloads GitHub license

TelegramBot is an unofficial library in PHP for use the Telegram APIs for bot

Install

Via Composer

$ composer require paranoiasystem/telegrambot-php-library

Usage

Send Message

<?php
	namespace Telegram;

    require_once __DIR__ . '/vendor/autoload.php'; 

	$bot = new TelegramBot('YOUR_BOT_API_TOKEN', 'YOUR_BOT_USERNAME');

	$bot->sendMessage('chat_id', 'text');

Send Photo

<?php
	namespace Telegram;

    require_once __DIR__ . '/vendor/autoload.php'; 

	$bot = new TelegramBot('YOUR_BOT_API_TOKEN', 'YOUR_BOT_USERNAME');

	$bot->sendPhoto('chat_id', 'path_to_photo');

	//or

	$bot->sendPhoto('chat_id', array('file_id'  => 'file_id_value'));

Bot Example

Set WebHook

<?php
	namespace Telegram;

    require_once __DIR__ . '/vendor/autoload.php'; 

    $bot = new TelegramBot('YOUR_BOT_API_TOKEN', 'YOUR_BOT_USERNAME');

    $response = $bot->setWebhook("https://url.to/hook.php"); //only https

	if($response->description == "Webhook was set")
		echo "Ok! The bot is ready!";
	else{
		echo "Ops! Error <br>";
		print_r($response);
	}
?>

BotCore (hook.php)

<?php
	namespace Telegram;

    require_once __DIR__ . '/vendor/autoload.php'; 

    $bot = new TelegramBot('YOUR_BOT_API_TOKEN', 'YOUR_BOT_USERNAME');

    $response = $bot->hook();

	$comand = $response->message->text;

	if(substr($comand, 0, strlen("/echo")) === "/echo")
		$bot->sendMessage($response->message->chat->id, str_replace("/echo", "", $comand));

	if(substr($comand, 0, strlen("/img")) === "/img")
		$bot->sendPhoto($response->message->chat->id, 'path_to_photo');
?>

About

TelegramBot is an unofficial library for use the Telegram APIs for bot

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages