Telegram TDLib Client
Build Telegram user-account or bot applications in Delphi/C++Builder. Wraps the official Telegram TDLib to expose authentication, chats, messages and update events.
Build Telegram user-account or bot applications in Delphi/C++Builder. Wraps the official Telegram TDLib to expose authentication, chats, messages and update events.
Delphi/C++Builder wrapper for the official Telegram TDLib (tdjson). Drives the authentication state machine, exposes typed message send/receive events, and delivers every other TDLib update through OnEvent.
TsgcTDLib_Telegram
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
Set Telegram.API.ApiId / ApiHash and Telegram.PhoneNumber, hook OnAuthenticationCode for the login flow, then send messages once OnAuthorizationStatus reports authorizationStateReady.
uses
sgcLibs;
var
Telegram: TsgcTDLib_Telegram;
begin
Telegram := TsgcTDLib_Telegram.Create(nil);
Telegram.Telegram.API.ApiId := '123456';
Telegram.Telegram.API.ApiHash := 'your-api-hash';
Telegram.Telegram.PhoneNumber := '+34600111222';
Telegram.OnAuthenticationCode := TelegramAuthenticationCode;
Telegram.OnAuthorizationStatus := TelegramAuthorizationStatus;
Telegram.OnMessageText := TelegramMessageText;
Telegram.Active := True;
end;
procedure TForm1.TelegramAuthenticationCode(Sender: TObject;
var Code: string);
begin
Code := InputBox('Telegram', 'Enter the code you received', '');
end;
procedure TForm1.TelegramAuthorizationStatus(Sender: TObject;
const Status: string);
begin
if Status = 'authorizationStateReady' then
Telegram.GetChats;
end;
procedure TForm1.TelegramMessageText(Sender: TObject;
MessageText: TsgcTelegramMessageText);
begin
Memo1.Lines.Add(MessageText.ChatId + ': ' + MessageText.Text);
Telegram.SendTextMessage(MessageText.ChatId, 'received!');
end;
// include: sgcLibs.hpp
TsgcTDLib_Telegram *Telegram = new TsgcTDLib_Telegram(this);
Telegram->Telegram->API->ApiId = "123456";
Telegram->Telegram->API->ApiHash = "your-api-hash";
Telegram->Telegram->PhoneNumber = "+34600111222";
Telegram->OnAuthenticationCode = TelegramAuthenticationCode;
Telegram->OnAuthorizationStatus = TelegramAuthorizationStatus;
Telegram->OnMessageText = TelegramMessageText;
Telegram->Active = true;
void __fastcall TForm1::TelegramAuthenticationCode(TObject *Sender, AnsiString &Code)
{
Code = InputBox("Telegram", "Enter the code you received", "");
}
void __fastcall TForm1::TelegramAuthorizationStatus(TObject *Sender, const AnsiString Status)
{
if (Status == "authorizationStateReady")
Telegram->GetChats();
}
void __fastcall TForm1::TelegramMessageText(TObject *Sender, TsgcTelegramMessageText *MessageText)
{
Memo1->Lines->Add(MessageText->ChatId + ": " + MessageText->Text);
Telegram->SendTextMessage(MessageText->ChatId, "received!");
}
A Delphi facade over the official TDLib (tdjson) shared library — same protocol the official Telegram clients use.
The component drives the TDLib authentication state machine: phone number, code, optional 2FA password, and persists the session under the local database directory.
SendTextMessage, SendPhotoMessage, SendVideoMessage, SendDocumentMessage and SendMessageAlbum cover the main TDLib message-content types.
GetChats, GetChat, SearchPublicChat and GetUser expose the Telegram address book and joined channels/groups as typed responses.
OnEvent delivers every TDLib updateXxx event — new messages, user typing, channel posts, edits, deletions — as a raw event name plus JSON for downstream routing, alongside the typed OnMessageText, OnNewChat and OnNewCallbackQuery events for common cases.
Uses the official tdjson.dll / libtdjson.so / libtdjson.dylib — same end-to-end encryption guarantees as the official Telegram client.
TDLib ships for Windows, macOS, Linux, Android and iOS. The component locates and loads the native library automatically per platform; you only handle the typed bridging through the events and methods above.
Authoritative sources for the API this component implements.
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.
| Online Help — API_Telegram Full property, method and event reference for this component. | Open | |
| Demo Project — Demos\50.Other\01.Telegram_Client Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |