PHP code example of matriphe / telegrambot
1. Go to this page and download the library: Download matriphe/telegrambot 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/ */
matriphe / telegrambot example snippets
key = '<fill_your_api_key_here>';
$chat_id = '<user_or_group_id>';
$telegram = new \Matriphe\Telegrambot\Telegrambot($apikey);
// Get bot info
$getme = $telegram->getMe();
var_dump($getme);
// Get bot messages received by bot. See user_id from here.
$updates = $telegram->getUpdates();
var_dump($updates);
// Send message to user.
$message = $telegram->sendMessage([
'chat_id' => $chat_id,
'text' => 'Today is '.date('Y-m-d H:i:s')
]);
var_dump($message);
// Upload file, use fopen function.
$filepath = '/home/matriphe/photo.jpg';
$photo = $telegram->sendPhoto([
'chat_id' => $chat_id,
'photo' => fopen($filepath, 'rb'),
'caption' => 'The caption goes here!'
]);
var_dump($photo);