This package is deprecated, please use PHPTelebot instead of. It's newer and better.
A Simple Telegram Bot based on the official Telegram Bot API
- PHP 5.3+
- Telegram Bot API Access Token - Talk to @BotFather and generate one. Documentation.
You can either add the package directly by firing this command
$ composer require radyakaze/telebot
You must set WebHook
Create set.php and put:
<?php
$token = 'BOT TOKEN';
$botname = 'BOT USERNAME';
require __DIR__.'/vendor/autoload.php';
$tg = new TeleBot\Api($token, $botname);
$tg->setWebhook('https://domain/path_to_hook.php');
And open your set.php via browser
After create hook.php and put:
<?php
$token = 'BOT TOKEN';
$botname = 'BOT USERNAME';
require __DIR__.'/vendor/autoload.php';
$tg = new TeleBot\Api($token, $botname);
// Simple command : /hello => Hello world!
$tg->cmd('hello', 'Hello world!');
// Simple command with parameter : /echo telebot => telebot
$tg->cmd('echo', function($text){
if (isset($text)) {
return $text;
} else {
return '/echo <text>';
}
});
$tg->run();
$tg->cmd('upload', array(
'type' => 'photo',
'send' => 'path/to/photo.jpg'
);
// OR
$tg->cmd('upload2', function($text) {
return array(
'type' => 'photo',
'send' => 'path/to/photo.jpg'
)
});
<?php
$tg->cmd('myloc', function($text) {
return array(
'type' => 'location',
'send' => array(-7.61, 109.51) // Gombong, Kebumen, Indonesia, you can integrate with google maps api
)
});
- text, optional: web_preview (default: true)
- photo, optional: caption
- video, optional: caption
- document
- audio
- location, required: send as array($latitude, $longitude)
TeleBot is under the MIT License
Created by Radya.