Skip to content

stievenk/TelegramAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Koyabu Telegram API Client (PHP)

koyabu/telegramapi adalah library PHP sederhana dan fleksibel untuk berkomunikasi dengan Telegram Bot API, mendukung pengiriman pesan, media, webhook, update, dan berbagai fitur Telegram lainnya.

Library ini dibangun menggunakan GuzzleHttp sebagai HTTP client.


πŸš€ Fitur Utama

  • Mengirim pesan text
  • Mengirim photo, video, audio, document, voice
  • Mengirim album (media group)
  • Edit message
  • Delete message
  • Mendapatkan update (long polling)
  • Mengatur webhook (setWebhook / deleteWebhook)
  • Mendapatkan file & membuat URL unduhan
  • Mendapatkan informasi bot (getMe)
  • Mengirim typing action (sendChatAction)

πŸ“₯ Instalasi

Install via Composer:

composer require koyabu/telegramapi

Atau tambahkan pada composer.json:

{
  "require": {
    "koyabu/telegramapi": "dev-master"
  }
}

πŸ›  Cara Menggunakan

1. Inisiasi Class

use Koyabu\TelegramAPI\Telegram;

$bot = new Telegram([
    'token'   => 'YOUR_TELEGRAM_BOT_TOKEN',
    'botname' => 'MyAwesomeBot'
]);

πŸ“€ Mengirim Pesan

1. Kirim Pesan Text

$bot->sendMessage(123456789, "Halo dunia!");

2. Kirim Photo

$bot->sendPhoto(123456789, './image.jpg', 'Ini contoh foto');

3. Kirim Document

$bot->sendDocument(123456789, './test.pdf', 'Berikut file PDF');

4. Kirim Video

$bot->sendVideo(123456789, './video.mp4', 'Video contoh');

5. Kirim Audio

$bot->sendAudio(123456789, './audio.mp3');

6. Kirim Voice Message

$bot->sendVoice(123456789, './voice.ogg');

7. Kirim Media Group (Album)

$bot->sendMediaGroup(123456789, [
    ['type' => 'photo', 'file' => './1.jpg', 'caption' => 'Foto 1'],
    ['type' => 'photo', 'file' => './2.jpg'],
    ['type' => 'document', 'file' => './file.pdf']
]);

✏ Edit & Delete Message

Edit Message

$bot->editMessageText(123456789, 45, "Teks diganti!");

Hapus Message

$bot->deleteMessage(123456789, 45);

πŸ”„ Mendapatkan Update (Long Polling)

$updates = $bot->getUpdates();
print_r($updates);

Jika ingin polling dari offset tertentu:

$bot->getUpdates($start = 50);

🌐 Webhook

Set Webhook

$bot->setWebhook("https://example.com/webhook-handler.php");

Delete Webhook

$bot->deleteWebhook();

Get Webhook Info

$info = $bot->getWebhookInfo();
print_r($info);

πŸ“ Mendapatkan File

1. Ambil informasi file

$file = $bot->getFile($file_id);
$file_path = $file['result']['file_path'];

2. Buat URL download file

$url = $bot->buildFileUrl($file_path);
echo $url;

πŸ§ͺ Contoh Webhook Handler (PHP)

require 'vendor/autoload.php';

use Koyabu\TelegramAPI\Telegram;

$bot = new Telegram([
    'token' => 'YOUR_BOT_TOKEN',
]);

$data = json_decode(file_get_contents('php://input'), true);

$chat_id = $data['message']['chat']['id'];
$text    = $data['message']['text'];

$bot->sendMessage($chat_id, "Anda berkata: $text");

πŸ“‚ Struktur Folder Direkomendasikan

project/
│── src/
β”‚   └── Telegram.php
│── public/
β”‚   └── webhook.php
│── composer.json
│── README.md

πŸ’¬ Dukungan & Kontribusi

Pull Request dipersilakan. Jika ingin menambah fitur Telegram lainnya, tinggalkan issue.


πŸ“„ Lisensi

MIT License β€” bebas digunakan untuk kebutuhan personal & komersial.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages