PHP code example of aki / yii2-bot-telegram
1. Go to this page and download the library: Download aki/yii2-bot-telegram library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aki / yii2-bot-telegram example snippets
'components' => [
'telegram' => [
'class' => 'aki\telegram\Telegram',
'botToken' => '112488045:AAGs6CVXgaqC92pvt1u0L6Azfsdfd',
]
]
Yii::$app->telegram->sendMessage([
'chat_id' => $chat_id,
'text' => 'test',
]);
Yii::$app->telegram->sendMessage([
'chat_id' => $chat_id,
'text' => 'this is test',
'reply_markup' => json_encode([
'inline_keyboard'=>[
[
['text'=>"refresh",'callback_data'=> time()]
]
]
]),
]);
Yii::$app->telegram->sendPhoto([
'chat_id' => $chat_id,
'photo' => Yii::$app->getBaseUrl().'/uploads/test.jpg',
'caption' => 'this is test'
]);
class SiteController extends Controller
{
public $enableCsrfValidation = false;
public function actionIndex()
{
$res = Yii::$app->telegram->sendMessage([
'chat_id' => $chat_id,
'text' => 'hello world!!'
]);
}
}
$res = Yii::$app->telegram->sendMessage([
'chat_id' => $telegram->input->message->chat->id,
'text' => "salam"
]);
use aki\telegram\base\Command;
Command::run("/start", function($telegram){
$result = $telegram->sendMessage([
'chat_id' => $telegram->input->message->chat->id,
"text" => "hello"
]);
});
php composer.phar