
Il s'agit d'un composant Delphi pour interagir avec l'API Bot Telegram. Il fournit un ensemble de fonctions pour effectuer diverses actions à l'aide de la plate-forme de bot Telegram.
Pour utiliser ce composant dans votre projet Delphi, suivez ces étapes:
DTelegram.dproj situé dans le dossier "Package" du code source du composant.DTelegram.bpl . Cette étape peut impliquer le clic droit sur le fichier du projet et la sélection de "compiler" puis "installer". | Fonction | Description | Exemple d'utilisation |
|---|---|---|
| Getme | Obtenez des informations sur le bot. | BotInfo := TelegramBot.GetMe; |
| Déconnexion | Connectez-vous à partir du bot. | LoggedOut := TelegramBot.LogOut; |
| Fermer | Fermez la connexion BOT. | Closed := TelegramBot.Close; |
| SendMessage | Envoyer un SMS. | Message := TelegramBot.SendMessage(ChatId, 'Hello, Telegram!'); |
| Message vers l'avant | Transférer un message. | ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId); |
| Copymssage | Copiez un message. | CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId); |
| Sendphoto | Envoyez une photo. | PhotoMessage := TelegramBot.SendPhoto(ChatId, 'path/to/photo.jpg', 'Check this out!'); |
| Envoyer par Sendaudio | Envoyer un fichier audio. | AudioMessage := TelegramBot.SendAudio(ChatId, 'path/to/audio.mp3', 'Listen to this!'); |
| SendDocument | Envoyer un document. | DocumentMessage := TelegramBot.SendDocument(ChatId, 'path/to/document.pdf'); |
| Sendvideo | Envoyez une vidéo. | VideoMessage := TelegramBot.SendVideo(ChatId, 'path/to/video.mp4'); |
| Sendanimation | Envoyer une animation (GIF). | AnimationMessage := TelegramBot.SendAnimation(ChatId, 'path/to/animation.gif'); |
| SendVoice | Envoyer un message vocal. | VoiceMessage := TelegramBot.SendVoice(ChatId, 'path/to/voice.ogg'); |
| SendvideOnote | Envoyer une note vidéo. | VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, 'path/to/videonote.mp4'); |
| SendLocation | Envoyer un emplacement. | LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude); |
| Sendvenue | Envoyez un lieu. | VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, 'Venue Title', 'Venue Address'); |
| Contac | Envoyer un contact. | ContactMessage := TelegramBot.SendContact(ChatId, '123456789', 'John Doe'); |
| Sendpoll | Envoyez un sondage. | PollMessage := TelegramBot.SendPoll(ChatId, 'Which is your favorite color?', ['Red', 'Green', 'Blue']); |
| Senddice | Envoyez un dés. | DiceMessage := TelegramBot.SendDice(ChatId, '?'); |
| Dossur | Obtenez des mises à jour du serveur. | Updates := TelegramBot.GetUpdates(100, -1, 0); |
| Getfile | Obtenez des informations sur un fichier. | FileInfo := TelegramBot.GetFile(FileId); |
| Banchatmember | Interdire un membre du chat. | Banned := TelegramBot.BanChatMember(ChatId, UserId); |
| Invainceur | Unpan un membre du chat. | UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId); |
| CreatechatinviteLink | Créez un lien d'invitation de chat. | InviteLink := TelegramBot.CreateChatInviteLink(ChatId); |
| RévokechatinviteLink | Révoquez un lien d'invitation de chat. | RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, 'your_invite_link'); |
| ExportchatinviteLink | Exporter un lien d'invitation de chat. | ExportedLink := TelegramBot.ExportChatInviteLink(ChatId); |
| Approvechatjoinrequest | Approuver une demande de jointure de chat. | Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId); |
| Déclincatjoinrequest | Refuser une demande de jointure de chat. | Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId); |
| Deletechatphoto | Supprimez la photo de chat. | PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId); |
| Setchattitle | Définissez le titre de chat. | TitleSet := TelegramBot.SetChatTitle(ChatId, 'New Title'); |
| Setchatdescription | Définissez la description du chat. | DescriptionSet := TelegramBot.SetChatDescription(ChatId, 'New Description'); |
| Se débarrasser de | Laissez le chat. | LeftChat := TelegramBot.LeaveChat(ChatId); |
| Getchat | Obtenez des informations sur le chat. | ChatInfo := TelegramBot.GetChat(ChatId); |
| Setmyname | Définissez le nom du bot. | NameSet := TelegramBot.SetMyName('New Bot Name'); |
| Getmyname | Obtenez le nom du bot. | BotName := TelegramBot.GetMyName(); |
| Setmydescription | Définissez la description du bot. | DescriptionSet := TelegramBot.SetMyDescription('New Bot Description'); |
| Getmydescription | Obtenez la description du bot. | BotDescription := TelegramBot.GetMyDescription(); |
| Geninlinekeyboard | Une réponse des claviers | Response := TelegramBot.GenInlineKeyBoard(AButtonList,NumberOfButtonPerRow); |
Vous devez créer un bot avant d'utiliser ce composant.
Pour le canal public, il est super facile de trouver son chatid.
Ex : https://t.me/abcdefg - > ChatId := @abcdefg;Obtenez des informations sur le bot.
var BotInfo := TelegramBot.GetMe;Connectez-vous à partir du bot.
var LoggedOut := TelegramBot.LogOut;Fermez la connexion BOT.
var Closed := TelegramBot.Close;Envoyer un SMS.
var Message := TelegramBot.SendMessage(ChatId, ' Hello, Telegram! ' );Transférer un message.
var ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId);Copiez un message.
var CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId);Envoyez une 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);Envoyer un fichier audio.
var AudioMessage := TelegramBot.SendAudio(ChatId, ' path/to/audio.mp3 ' , ' Listen to this! ' );Envoyer un document.
var DocumentMessage := TelegramBot.SendDocument(ChatId, ' path/to/document.pdf ' );Envoyez une vidéo.
var VideoMessage := TelegramBot.SendVideo(ChatId, ' path/to/video.mp4 ' );Envoyer une animation (GIF).
var AnimationMessage := TelegramBot.SendAnimation(ChatId, ' path/to/animation.gif ' );Envoyer un message vocal.
var VoiceMessage := TelegramBot.SendVoice(ChatId, ' path/to/voice.ogg ' );Envoyer une note vidéo.
var VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, ' path/to/videonote.mp4 ' );Envoyer un emplacement.
var LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude);Envoyez un lieu.
var VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, ' Venue Title ' , ' Venue Address ' );Envoyer un contact.
var ContactMessage := TelegramBot.SendContact(ChatId, ' 123456789 ' , ' John Doe ' );Envoyez un sondage.
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);Envoyez un dés.
MyEmoji := TEmojiDice.Basketball;
var DiceMessage := TelegramBot.SendDice(ChatId, MyEmoji);Obtenez des mises à jour du serveur.
// By Default : Limit = 100; OffSet = -1; TimeOut = 0
var Updates := TelegramBot.GetUpdates(limit,AOffSet,ATimeOut);
Obtenez des informations sur un fichier.
var FileInfo := TelegramBot.GetFile(FileId);Interdire un membre du chat.
var Banned := TelegramBot.BanChatMember(ChatId, UserId);Unpan un membre du chat.
var UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId);Créez un lien d'invitation de chat.
var InviteLink := TelegramBot.CreateChatInviteLink(ChatId);Révoquez un lien d'invitation de chat.
var RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, ' your_invite_link ' );Exporter un lien d'invitation de chat.
var ExportedLink := TelegramBot.ExportChatInviteLink(ChatId);Approuver une demande de jointure de chat.
var Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId);Refuser une demande de jointure de chat.
var Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId);Supprimez la photo de chat.
var PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId);Définissez le titre de chat.
var TitleSet := TelegramBot.SetChatTitle(ChatId, ' New Title ' );Définissez la description du chat.
var DescriptionSet := TelegramBot.SetChatDescription(ChatId, ' New Description ' );Laissez le chat.
var LeftChat := TelegramBot.LeaveChat(ChatId);Obtenez des informations sur le chat.
var ChatInfo := TelegramBot.GetChat(ChatId);Définissez le nom du bot.
var NameSet := TelegramBot.SetMyName( ' New Bot Name ' );Obtenez le nom du bot.
var BotName := TelegramBot.GetMyName();Définissez la description du bot.
var DescriptionSet := TelegramBot.SetMyDescription( ' New Bot Description ' );Obtenez la description du bot.
var BotDescription := TelegramBot.GetMyDescription();Activer les claviers en ligne pour les actions interactives. Les claviers en ligne des boutons de support qui peuvent fonctionner en coulisses ou ouvrir différentes interfaces, y compris les boutons d'URL.
L'utilisation de TemoJIConstants a besoin d'une troisième partie de l'unité https://github.com/aso14/delphi-unicode-emoji
// Example usage of Inline Keyboards
var
LButtonList : TList <TTelegramInlineKeyBoardButton>;
begin
LButtonList := TList<TTelegramInlineKeyBoardButton>.Create;
// Create Button without Emoji
var LButton1 := TTelegramInlineKeyBoardButton.Create;
LButton1.text := ' Delphi Telegram ' ;
LButton1.url := ' https://github.com/aso14/DTelegram ' ;
// Create Button with Emoji
var LButton2 := TTelegramInlineKeyBoardButton.Create;
LButton2.text := ' Delphi UI ' + TEmojiConstants.UpsideDownFace;
LButton2.url := ' https://t.me/delphui ' ;
var LButton3 := TTelegramInlineKeyBoardButton.Create;
LButton3.text := ' Youtube ' +TEmojiConstants.WinkingFace;
LButton3.url := ' https://www.youtube.com/@uidelphi ' ;
LButtonList.Add(LButton1);
LButtonList.Add(LButton2);
LButtonList.Add(LButton3);
// If ALimitValue = 3, the maximun number of Button per row will be 3
var Response := TelegramBot.GenInlineKeyBoard(LButtonList, 3 );
var Option := TStringList.Create;
Option.Add( ' reply_markup= ' +Response);
TelegramBot.SendMessage( ' @chatId ' , ' Text ' ,Option);
end ;Cette bibliothèque est publiée sous la licence MIT.
N'hésitez pas à contribuer, à ouvrir des problèmes ou à fournir des commentaires!