Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

fastTelega

Delphi library for Telegram Bot API

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

fastTelega

Delphi library for Telegram Bot API.

This library is still under development and does not implement full functionality but you can already use it to create simple bots.

And so far only the mechanism is available long polling.

Documentation

  • Documentation (*.chm) is located here.
  • The deepwiki documentation is more detailed and deep-searchable using AI here.

Example

Example echo bot which sends everything it receives:

pascal
program Echobot_Delphi;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils,
  fastTelega.AvailableTypes,
  fastTelega.Bot,
  fastTelega.EventBroadcaster,
  fastTelega.LongPoll;

var
  Bot: TftBot;
  LongPoll: TftLongPoll;

begin
  try
    Bot := TftBot.Create('BOT_TOKEN',
      'https://api.telegram.org');
    Bot.Events.OnCommand('start',
      procedure(const FTMessage: TObject)
      begin
        Bot.API.sendMessage(TftMessage(FTMessage).Chat.id, 'Hi!');
      end);
    Bot.Events.OnAnyMessage(
      procedure(const FTMessage: TObject)
      begin
        Writeln('User wrote ', TftMessage(FTMessage).text);
        if Pos('/start', TftMessage(FTMessage).text) > 0 then
          Exit;
        Bot.API.sendMessage(TftMessage(FTMessage).Chat.id,
          'Your message is: ' + TftMessage(FTMessage).text);
      end);
    try
      Writeln('Bot username: ' + Bot.API.getMe.username);
      Bot.API.deleteWebhook();

      LongPoll := TftLongPoll.Create(Bot);
      while (True) do
      begin
        Writeln('Long poll started\n');
        LongPoll.start();
      end
    except
      on E: Exception do
         Writeln(E.ClassName, ': ', E.Message);
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;

end.

All other examples are located here.