
Este es un componente de Delphi para interactuar con la API BOT Telegram. Proporciona un conjunto de funciones para realizar diversas acciones utilizando la plataforma Bot Telegram.
Para usar este componente en su proyecto Delphi, siga estos pasos:
DTelegram.dproj ubicado en la carpeta "paquete" del código fuente del componente.DTelegram.bpl . Este paso puede implicar hacer clic derecho en el archivo del proyecto y seleccionar "compilar" y luego "instalar". | Función | Descripción | Uso de ejemplo |
|---|---|---|
| GetMe | Obtenga información sobre el bot. | BotInfo := TelegramBot.GetMe; |
| Cierre de sesión | Iniciar sesión desde el bot. | LoggedOut := TelegramBot.LogOut; |
| Cerca | Cierre la conexión BOT. | Closed := TelegramBot.Close; |
| Sendmessage | Envía un mensaje de texto. | Message := TelegramBot.SendMessage(ChatId, 'Hello, Telegram!'); |
| Avenente | Reenviar un mensaje. | ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId); |
| Topimesaje | Copiar un mensaje. | CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId); |
| Sendphoto | Envía una foto. | PhotoMessage := TelegramBot.SendPhoto(ChatId, 'path/to/photo.jpg', 'Check this out!'); |
| Sendudio | Enviar un archivo de audio. | AudioMessage := TelegramBot.SendAudio(ChatId, 'path/to/audio.mp3', 'Listen to this!'); |
| SendDocument | Enviar un documento. | DocumentMessage := TelegramBot.SendDocument(ChatId, 'path/to/document.pdf'); |
| Sendvideo | Envía un video. | VideoMessage := TelegramBot.SendVideo(ChatId, 'path/to/video.mp4'); |
| Sendanimation | Envía una animación (GIF). | AnimationMessage := TelegramBot.SendAnimation(ChatId, 'path/to/animation.gif'); |
| SendVoice | Envía un mensaje de voz. | VoiceMessage := TelegramBot.SendVoice(ChatId, 'path/to/voice.ogg'); |
| Sendvideonote | Envía una nota de video. | VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, 'path/to/videonote.mp4'); |
| SendLocation | Enviar una ubicación. | LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude); |
| Sendvenue | Envía un lugar. | VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, 'Venue Title', 'Venue Address'); |
| Sendcontact | Enviar un contacto. | ContactMessage := TelegramBot.SendContact(ChatId, '123456789', 'John Doe'); |
| SendPoll | Envía una encuesta. | PollMessage := TelegramBot.SendPoll(ChatId, 'Which is your favorite color?', ['Red', 'Green', 'Blue']); |
| Senddice | Envía un dados. | DiceMessage := TelegramBot.SendDice(ChatId, '?'); |
| Atacar | Obtenga actualizaciones del servidor. | Updates := TelegramBot.GetUpdates(100, -1, 0); |
| GetFile | Obtenga información sobre un archivo. | FileInfo := TelegramBot.GetFile(FileId); |
| Banchatmember | Prohibir a un miembro del chat. | Banned := TelegramBot.BanChatMember(ChatId, UserId); |
| Bandeja | Desacreditar un miembro del chat. | UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId); |
| Createechatinvitelink | Crea un enlace de invitación de chat. | InviteLink := TelegramBot.CreateChatInviteLink(ChatId); |
| Revokechatinvitelink | Revocar un enlace de invitación de chat. | RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, 'your_invite_link'); |
| ExportChatinVitelink | Exportar un enlace de invitación de chat. | ExportedLink := TelegramBot.ExportChatInviteLink(ChatId); |
| Aprobación de aprobación | Aprobar una solicitud de unión de chat. | Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId); |
| DecletareRoinRequest | Rechazar una solicitud de unión de chat. | Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId); |
| Deletechatphoto | Elimina la foto de chat. | PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId); |
| Setchattitle | Establezca el título de chat. | TitleSet := TelegramBot.SetChatTitle(ChatId, 'New Title'); |
| SetchatDescription | Establezca la descripción del chat. | DescriptionSet := TelegramBot.SetChatDescription(ChatId, 'New Description'); |
| Leavechat | Deja el chat. | LeftChat := TelegramBot.LeaveChat(ChatId); |
| Getchat | Obtenga información sobre el chat. | ChatInfo := TelegramBot.GetChat(ChatId); |
| Setmyname | Establezca el nombre del bot. | NameSet := TelegramBot.SetMyName('New Bot Name'); |
| GetMyname | Obtenga el nombre del bot. | BotName := TelegramBot.GetMyName(); |
| Setmydescription | Establezca la descripción del bot. | DescriptionSet := TelegramBot.SetMyDescription('New Bot Description'); |
| GetMyDescription | Obtenga la descripción del bot. | BotDescription := TelegramBot.GetMyDescription(); |
| Geninlinekeyboard | Una respuesta teclados | Response := TelegramBot.GenInlineKeyBoard(AButtonList,NumberOfButtonPerRow); |
Debe crear un bot antes de usar este componente.
Para el canal público es muy fácil de encontrar su chatid.
Ex : https://t.me/abcdefg - > ChatId := @abcdefg;Obtenga información sobre el bot.
var BotInfo := TelegramBot.GetMe;Iniciar sesión desde el bot.
var LoggedOut := TelegramBot.LogOut;Cierre la conexión BOT.
var Closed := TelegramBot.Close;Envía un mensaje de texto.
var Message := TelegramBot.SendMessage(ChatId, ' Hello, Telegram! ' );Reenviar un mensaje.
var ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId);Copiar un mensaje.
var CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId);Envía una foto.
// 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);Enviar un archivo de audio.
var AudioMessage := TelegramBot.SendAudio(ChatId, ' path/to/audio.mp3 ' , ' Listen to this! ' );Enviar un documento.
var DocumentMessage := TelegramBot.SendDocument(ChatId, ' path/to/document.pdf ' );Envía un video.
var VideoMessage := TelegramBot.SendVideo(ChatId, ' path/to/video.mp4 ' );Envía una animación (GIF).
var AnimationMessage := TelegramBot.SendAnimation(ChatId, ' path/to/animation.gif ' );Envía un mensaje de voz.
var VoiceMessage := TelegramBot.SendVoice(ChatId, ' path/to/voice.ogg ' );Envía una nota de video.
var VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, ' path/to/videonote.mp4 ' );Enviar una ubicación.
var LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude);Envía un lugar.
var VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, ' Venue Title ' , ' Venue Address ' );Enviar un contacto.
var ContactMessage := TelegramBot.SendContact(ChatId, ' 123456789 ' , ' John Doe ' );Envía una encuesta.
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);Envía un dados.
MyEmoji := TEmojiDice.Basketball;
var DiceMessage := TelegramBot.SendDice(ChatId, MyEmoji);Obtenga actualizaciones del servidor.
// By Default : Limit = 100; OffSet = -1; TimeOut = 0
var Updates := TelegramBot.GetUpdates(limit,AOffSet,ATimeOut);
Obtenga información sobre un archivo.
var FileInfo := TelegramBot.GetFile(FileId);Prohibir a un miembro del chat.
var Banned := TelegramBot.BanChatMember(ChatId, UserId);Desacreditar un miembro del chat.
var UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId);Crea un enlace de invitación de chat.
var InviteLink := TelegramBot.CreateChatInviteLink(ChatId);Revocar un enlace de invitación de chat.
var RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, ' your_invite_link ' );Exportar un enlace de invitación de chat.
var ExportedLink := TelegramBot.ExportChatInviteLink(ChatId);Aprobar una solicitud de unión de chat.
var Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId);Rechazar una solicitud de unión de chat.
var Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId);Elimina la foto de chat.
var PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId);Establezca el título de chat.
var TitleSet := TelegramBot.SetChatTitle(ChatId, ' New Title ' );Establezca la descripción del chat.
var DescriptionSet := TelegramBot.SetChatDescription(ChatId, ' New Description ' );Deja el chat.
var LeftChat := TelegramBot.LeaveChat(ChatId);Obtenga información sobre el chat.
var ChatInfo := TelegramBot.GetChat(ChatId);Establezca el nombre del bot.
var NameSet := TelegramBot.SetMyName( ' New Bot Name ' );Obtenga el nombre del bot.
var BotName := TelegramBot.GetMyName();Establezca la descripción del bot.
var DescriptionSet := TelegramBot.SetMyDescription( ' New Bot Description ' );Obtenga la descripción del bot.
var BotDescription := TelegramBot.GetMyDescription();Habilite teclados en línea para acciones interactivas. Los teclados en línea admiten botones que pueden funcionar detrás de escena o abrir diferentes interfaces, incluidos los botones URL.
El uso de Temojiconstants necesita una tercera unidad 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 ;Esta biblioteca se lanza bajo la licencia MIT.
¡Siéntase libre de contribuir, abrir problemas o proporcionar comentarios!