PHP code example of firedemonsu / yii2-bot-telegram

1. Go to this page and download the library: Download firedemonsu/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/ */

    

firedemonsu / 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' => 'path/to/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!!' 
        ]);
       return $this->render('index');
    }
}

$res = Yii::$app->telegram->sendMessage([
	'chat_id' => $telegram->input->message->chat->id,
	'text' => "salam"
]);

php composer.phar