Telegram Client Component: sgcSocial | eSeGeCe

Telegram Client

TsgcTDLib_Telegram is a full Telegram client built on the official TDLib (Telegram Database Library). It signs in with a user account or a bot token, so it reaches far beyond the Bot API: your own chats, groups, channels, secret chats, media, payments and search. The same component and the same API in Delphi and C++ Builder.

TsgcTDLib_Telegram

Set Telegram.API.ApiId and ApiHash, sign in with Telegram.PhoneNumber or Telegram.BotToken, wire the message events, then set Active to True.

Component class

TsgcTDLib_Telegram

API

Official TDLib (Telegram Database Library)

Platforms

Windows, macOS, Linux 64-bit, Android, iOS

Languages

Delphi, C++ Builder

Also inside sgcWebSockets. The Telegram client also ships inside sgcWebSockets editions from Standard up. sgcSocial is the standalone package, the sgcWebSockets Core runtime is bundled in.

Sign in, receive, reply

Set your api_id and api_hash from my.telegram.org, sign in with a phone number, and echo inbound text messages. TsgcTDLib_Telegram is declared in the sgcLibs unit.

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->OnMessageText        = TelegramMessageText;

Telegram->Active = true;

void __fastcall TForm1::TelegramAuthenticationCode(TObject *Sender,
    UnicodeString &Code)
{
  Code = InputBox("Telegram", "Enter the code you received", "");
}

void __fastcall TForm1::TelegramMessageText(TObject *Sender,
    TsgcTelegramMessageText *MessageText)
{
  Memo1->Lines->Add(MessageText->ChatId + ": " + MessageText->Text);
  Telegram->SendTextMessage(MessageText->ChatId, "received!");
}

Key properties & methods

The members you reach for most often.

Authentication

Telegram.API.ApiId and ApiHash identify your application. Sign in with Telegram.PhoneNumber, or with Telegram.BotToken for a bot. OnAuthenticationCode asks for the login code, OnAuthenticationPassword for the 2FA password, and OnRegisterUser covers new accounts.

Session state

OnConnectionStatus and OnAuthorizationStatus report the raw TDLib states. Telegram.DatabaseDirectory persists the session, so the next start does not ask for a code again.

Sending

SendTextMessage and SendRichTextMessage for text, SendDocumentMessage, SendPhotoMessage and SendVideoMessage for media, SendMessageAlbum for grouped media and SendInvoiceMessage for payments.

Managing messages

EditTextMessage, DeleteMessages, ForwardMessages and PinChatMessage cover the lifecycle after sending.

Chats and groups

CreatePrivateChat, CreateNewBasicGroupChat, CreateNewSupergroupChat and CreateNewSecretChat create conversations. JoinChat and JoinChatByInviteLink join existing ones.

Search and files

SearchChats, SearchMessages, SearchContacts and SearchPublicChats query the network. DownloadFile fetches any file TDLib references.

Keyboards

Inline keyboards with callback and URL buttons, answered through AnswerCallbackQuery and observed with OnNewCallbackQuery. Reply keyboards offer text, request-location and request-phone-number buttons.

Bots and payments

AnswerInlineQuery answers inline queries, AnswerPreCheckoutQuery and SendPaymentForm drive the payments flow.

Events and escape hatch

OnMessageText, OnMessageDocument, OnMessagePhoto and OnMessageVideo deliver typed messages, with OnMessageSponsored, OnNewChat and raw OnEvent alongside. SendCustomRequest sends any TDLib JSON request.

Proxies

HTTP, SOCKS5 and MTProto proxies route the TDLib connection through your network path of choice.

Keep exploring

sgcSocial OverviewBoth components, editions and licensing at a glance.
Feature Matrix: TelegramEvery capability of this component in table form.
Telegram API Deep DiveThe API reference page, with online help and PDF links.
Blog: Telegram Client for DelphiA walkthrough of building a Telegram client with this component.
Blog: Android Telegram ClientRunning the TDLib client on Android.
Blog: iOS Telegram ClientRunning the TDLib client on iOS.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and send your first Telegram message from Delphi or C++ Builder.