Skip to content

API Reference

All classes live under the Pam\TelegramWeb namespace. This page documents version 0.3.0.

new Client(ClientOptions $options = new ClientOptions(), ?Session $session = null)

Method Description
initialize() Opens Telegram Web. Called by run() and pump().
run(?Closure $shouldStop = null) Delivers events until stop(), a signal, or $shouldStop() returns true.
pump(float $timeout = 1.0) Delivers events for up to $timeout seconds.
stop() Ends run().
waitUntilReady(float $timeout = 120.0) Blocks until logged in.
isReady() Whether the account is logged in.
submitPassword(string $password) Answers the two-step verification prompt.
logout() Ends the Telegram session.
close() Closes the browser; the login stays saved.

onQrCode(), onPasswordRequired(), onReady(), onMessage(), onMessageEdited(), onMessagesDeleted(), onLoggedOut(), and onError(). See Events.

Method Returns
getMe() User
getChats(int $limit = 50) list<Chat>
getMessages(int $chatId, int $limit = 50) list<Message>, newest first
sendMessage(int $chatId, string $text, array $options = []) ?Message
sendFile(int $chatId, string $path, string $caption = '', array $options = []) ?Message
sendFileContents(int $chatId, string $contents, string $fileName, string $caption = '', array $options = []) ?Message
downloadMedia(int $chatId, int $messageId) DownloadedFile
editMessage(int $chatId, int $messageId, string $text) void
deleteMessages(int $chatId, array $messageIds, bool $forEveryone = true) void
forwardMessages(int $fromChatId, array $messageIds, int $toChatId, array $options = []) void
react(int $chatId, int $messageId, ?string $emoji) void
markAsRead(int $chatId) void
sendChatAction(int $chatId, ChatAction $action = ChatAction::Typing) void
Method Returns
getMembers(int $chatId, int $limit = 200) list<User>
resolveUsername(string $username) int chat ID
join(string $usernameOrLink) int chat ID
createGroup(string $title, string $about = '', array $userIds = []) int chat ID
createChannel(string $title, string $about = '') int chat ID
inviteLink(int $chatId) string
leave(int $chatId) void
deleteChat(int $chatId) void
invoke(string $method, array $params = []) mixed
inputPeer(int $chatId) array
Option Default Description
sessionDirectory null Browser profile; defaults to ./.pam-telegram-web/session. One per account.
browserExecutable null Chrome path; auto-detected when null.
headless true Run Chrome without a window.
browserTimeoutSeconds 30.0 Time allowed for Chrome to start.
browserArguments [] Extra Chrome flags.
webUrl 'https://web.telegram.org/k/' Telegram Web URL; must use HTTPS.
requestTimeoutSeconds 30.0 Time limit for one bridge call.
userAgent null null uses a desktop Chrome user agent in headless mode, false keeps Chrome’s own, a string sets a custom one.
fileTimeoutSeconds 300.0 Time limit for one upload or download.
maxDownloadBytes 104857600 (100 MB) Largest file downloadMedia() accepts.
Class Properties and methods
Chat id, type, title, username, unreadCount, pinned, lastMessage, raw; sendMessage(), sendFile(), fetchMessages(), markAsRead(), sendAction(), members(), leave()
Message id, chatId, fromId, fromName, text, date, outgoing, hasMedia, chatTitle, raw, mediaType, fileName, mimeType, fileSize, replyToId, editDate; reply(), replyWithFile(), edit(), delete(), forwardTo(), react(), download()
User id, firstName, lastName, username, phone, isBot, raw; name()
DownloadedFile name, mimeType, contents; size(), saveTo(string $path)
QrCode decode(string $png), render(string $data, string $indent = ' ')
Enum Cases
ChatType Private, Bot, Group, Channel
MediaType Photo, Video, VideoNote, Animation, Audio, Voice, Sticker, Document, Location, Contact, Poll, Other
ChatAction Typing, UploadPhoto, UploadVideo, UploadDocument, RecordVoice, ChooseSticker, Cancel

Exception\TelegramWebException is thrown when Telegram Web fails or rejects a call, with Telegram’s error text when available. Invalid arguments, such as empty message text or an unreadable file, throw InvalidArgumentException.