This is a Delphi library for interacting with the Telegram Bot API. It provides a set of functions to perform various actions using the Telegram Bot platform.
Compatibility: VCL, FMX
Tested on Delphi: 11 Alexandria CE
Version: 1.0.0
Developer: Silas AÏKO
To use this library in your Delphi project, follow these steps:
- Clone the library repository or download the source code as a ZIP file from the GitHub repository.
- Unzip the files into a directory of your choice.
- Open RAD Studio and navigate to "Tools > Options... > Language > Delphi."
- Under the "Library" section, add the "\Sources" path from the library source code to the library paths for each platform you want to compile.
- Open the
DTelegram.dproj
file located in the "Package" folder of the library source code. - Compile and install the package
DTelegram.bpl
. This step may involve right-clicking on the project file and selecting "Compile" and then "Install."
Function | Description | Example Usage |
---|---|---|
GetMe | Get information about the bot. | BotInfo := TelegramBot.GetMe; |
LogOut | Log out from the bot. | LoggedOut := TelegramBot.LogOut; |
Close | Close the bot connection. | Closed := TelegramBot.Close; |
SendMessage | Send a text message. | Message := TelegramBot.SendMessage(ChatId, 'Hello, Telegram!'); |
ForwardMessage | Forward a message. | ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId); |
CopyMessage | Copy a message. | CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId); |
SendPhoto | Send a photo. | PhotoMessage := TelegramBot.SendPhoto(ChatId, 'path/to/photo.jpg', 'Check this out!'); |
SendAudio | Send an audio file. | AudioMessage := TelegramBot.SendAudio(ChatId, 'path/to/audio.mp3', 'Listen to this!'); |
SendDocument | Send a document. | DocumentMessage := TelegramBot.SendDocument(ChatId, 'path/to/document.pdf'); |
SendVideo | Send a video. | VideoMessage := TelegramBot.SendVideo(ChatId, 'path/to/video.mp4'); |
SendAnimation | Send an animation (GIF). | AnimationMessage := TelegramBot.SendAnimation(ChatId, 'path/to/animation.gif'); |
SendVoice | Send a voice message. | VoiceMessage := TelegramBot.SendVoice(ChatId, 'path/to/voice.ogg'); |
SendVideoNote | Send a video note. | VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, 'path/to/videonote.mp4'); |
SendLocation | Send a location. | LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude); |
SendVenue | Send a venue. | VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, 'Venue Title', 'Venue Address'); |
SendContact | Send a contact. | ContactMessage := TelegramBot.SendContact(ChatId, '123456789', 'John Doe'); |
SendPoll | Send a poll. | PollMessage := TelegramBot.SendPoll(ChatId, 'Which is your favorite color?', ['Red', 'Green', 'Blue']); |
SendDice | Send a dice. | DiceMessage := TelegramBot.SendDice(ChatId, '🎲'); |
GetUpdates | Get updates from the server. | Updates := TelegramBot.GetUpdates(100, -1, 0); |
GetFile | Get information about a file. | FileInfo := TelegramBot.GetFile(FileId); |
BanChatMember | Ban a chat member. | Banned := TelegramBot.BanChatMember(ChatId, UserId); |
UnBanChatMember | Unban a chat member. | UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId); |
CreateChatInviteLink | Create a chat invite link. | InviteLink := TelegramBot.CreateChatInviteLink(ChatId); |
RevokeChatInviteLink | Revoke a chat invite link. | RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, 'your_invite_link'); |
ExportChatInviteLink | Export a chat invite link. | ExportedLink := TelegramBot.ExportChatInviteLink(ChatId); |
ApproveChatJoinRequest | Approve a chat join request. | Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId); |
DeclineChatJoinRequest | Decline a chat join request. | Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId); |
DeleteChatPhoto | Delete the chat photo. | PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId); |
SetChatTitle | Set the chat title. | TitleSet := TelegramBot.SetChatTitle(ChatId, 'New Title'); |
SetChatDescription | Set the chat description. | DescriptionSet := TelegramBot.SetChatDescription(ChatId, 'New Description'); |
LeaveChat | Leave the chat. | LeftChat := TelegramBot.LeaveChat(ChatId); |
GetChat | Get information about the chat. | ChatInfo := TelegramBot.GetChat(ChatId); |
SetMyName | Set the bot's name. | NameSet := TelegramBot.SetMyName('New Bot Name'); |
GetMyName | Get the bot's name. | BotName := TelegramBot.GetMyName(); |
SetMyDescription | Set the bot's description. | DescriptionSet := TelegramBot.SetMyDescription('New Bot Description'); |
GetMyDescription | Get the bot's description. | BotDescription := TelegramBot.GetMyDescription(); |
You need to create a bot before using this component.
- How Create your own bot : https://core.telegram.org/bots#how-do-i-create-a-bot
- Telegram Bot API documentation : https://core.telegram.org/bots/api
For Public channel is super easy to find its ChatId.
Ex : https://t.me/abcdefg -> ChatId := @abcdefg;
Get information about the bot.
var BotInfo := TelegramBot.GetMe;
Log out from the bot.
var LoggedOut := TelegramBot.LogOut;
Close the bot connection.
var Closed := TelegramBot.Close;
Send a text message.
var Message := TelegramBot.SendMessage(ChatId, 'Hello, Telegram!');
Forward a message.
var ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId);
Copy a message.
var CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId);
Send a photo.
// How use AOptions
var AOption : TTelegramDic; // TDictionary<string,string>;
AOption := TTelegramDic.Create;
AOption.Add('protect_content','1'); // Example
var PhotoMessage := TelegramBot.SendPhoto(ChatId, 'path/to/photo.jpg', 'Check this out!',AOption);
Send an audio file.
var AudioMessage := TelegramBot.SendAudio(ChatId, 'path/to/audio.mp3', 'Listen to this!');
Send a document.
var DocumentMessage := TelegramBot.SendDocument(ChatId, 'path/to/document.pdf');
Send a video.
var VideoMessage := TelegramBot.SendVideo(ChatId, 'path/to/video.mp4');
Send an animation (GIF).
var AnimationMessage := TelegramBot.SendAnimation(ChatId, 'path/to/animation.gif');
Send a voice message.
var VoiceMessage := TelegramBot.SendVoice(ChatId, 'path/to/voice.ogg');
Send a video note.
var VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, 'path/to/videonote.mp4');
Send a location.
var LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude);
Send a venue.
var VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, 'Venue Title', 'Venue Address');
Send a contact.
var ContactMessage := TelegramBot.SendContact(ChatId, '123456789', 'John Doe');
Send a poll.
var ListAnswers := TStringList.Create;
ListAnswers.Add('Red');
ListAnswers.Add('Green');
ListAnswers.Add('Blue');
//How use Option Argument
var Option := TStringList.Create;
Option.Add('allows_multiple_answers=1');
Option.Add('protect_content=true');
var PollMessage := TelegramBot.SendPoll(ChatId, 'Which is your favorite color?', ListAnswers,Option);
Send a dice.
MyEmoji := TEmojiDice.Basketball;
var DiceMessage := TelegramBot.SendDice(ChatId, MyEmoji);
Get updates from the server.
//By Default : Limit = 100; OffSet = -1; TimeOut = 0
var Updates := TelegramBot.GetUpdates(limit,AOffSet,ATimeOut);
Get information about a file.
var FileInfo := TelegramBot.GetFile(FileId);
Ban a chat member.
var Banned := TelegramBot.BanChatMember(ChatId, UserId);
Unban a chat member.
var UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId);
Create a chat invite link.
var InviteLink := TelegramBot.CreateChatInviteLink(ChatId);
Revoke a chat invite link.
var RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, 'your_invite_link');
Export a chat invite link.
var ExportedLink := TelegramBot.ExportChatInviteLink(ChatId);
Approve a chat join request.
var Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId);
Decline a chat join request.
var Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId);
Delete the chat photo.
var PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId);
Set the chat title.
var TitleSet := TelegramBot.SetChatTitle(ChatId, 'New Title');
Set the chat description.
var DescriptionSet := TelegramBot.SetChatDescription(ChatId, 'New Description');
Leave the chat.
var LeftChat := TelegramBot.LeaveChat(ChatId);
Get information about the chat.
var ChatInfo := TelegramBot.GetChat(ChatId);
Set the bot's name.
var NameSet := TelegramBot.SetMyName('New Bot Name');
Get the bot's name.
var BotName := TelegramBot.GetMyName();
Set the bot's description.
var DescriptionSet := TelegramBot.SetMyDescription('New Bot Description');
Get the bot's description.
var BotDescription := TelegramBot.GetMyDescription();
This library is released under the MIT License.
Feel free to contribute, open issues, or provide feedback!