
Este é um componente Delphi para interagir com a API do Telegram Bot. Ele fornece um conjunto de funções para executar várias ações usando a plataforma Bot Telegram.
Para usar este componente no seu projeto Delphi, siga estas etapas:
DTelegram.dproj localizado na pasta "pacote" do código -fonte do componente.DTelegram.bpl . Esta etapa pode envolver clicar com o botão direito do mouse no arquivo do projeto e selecionar "compilar" e depois "instalar". | Função | Descrição | Exemplo de uso |
|---|---|---|
| GetMe | Obtenha informações sobre o bot. | BotInfo := TelegramBot.GetMe; |
| Logout | Faça logon no bot. | LoggedOut := TelegramBot.LogOut; |
| Fechar | Feche a conexão bot. | Closed := TelegramBot.Close; |
| SendMessage | Envie uma mensagem de texto. | Message := TelegramBot.SendMessage(ChatId, 'Hello, Telegram!'); |
| ForwardMessage | Encaminhar uma mensagem. | ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId); |
| Copymessage | Copie uma mensagem. | CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId); |
| Sendphoto | Envie uma foto. | PhotoMessage := TelegramBot.SendPhoto(ChatId, 'path/to/photo.jpg', 'Check this out!'); |
| Sendaudio | Envie um arquivo de áudio. | AudioMessage := TelegramBot.SendAudio(ChatId, 'path/to/audio.mp3', 'Listen to this!'); |
| SendDocument | Envie um documento. | DocumentMessage := TelegramBot.SendDocument(ChatId, 'path/to/document.pdf'); |
| Sendvideo | Envie um vídeo. | VideoMessage := TelegramBot.SendVideo(ChatId, 'path/to/video.mp4'); |
| Sendanimation | Envie uma animação (GIF). | AnimationMessage := TelegramBot.SendAnimation(ChatId, 'path/to/animation.gif'); |
| Sendvoice | Envie uma mensagem de voz. | VoiceMessage := TelegramBot.SendVoice(ChatId, 'path/to/voice.ogg'); |
| Sendvideonote | Envie uma nota de vídeo. | VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, 'path/to/videonote.mp4'); |
| SendLocation | Envie um local. | LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude); |
| SendVenue | Envie um local. | VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, 'Venue Title', 'Venue Address'); |
| SendContact | Envie um contato. | ContactMessage := TelegramBot.SendContact(ChatId, '123456789', 'John Doe'); |
| Sendpoll | Envie uma pesquisa. | PollMessage := TelegramBot.SendPoll(ChatId, 'Which is your favorite color?', ['Red', 'Green', 'Blue']); |
| SendDice | Envie um dado. | DiceMessage := TelegramBot.SendDice(ChatId, '?'); |
| Getupdates | Obtenha atualizações do servidor. | Updates := TelegramBot.GetUpdates(100, -1, 0); |
| Getfile | Obtenha informações sobre um arquivo. | FileInfo := TelegramBot.GetFile(FileId); |
| Banchatmember | Banir um membro do bate -papo. | Banned := TelegramBot.BanChatMember(ChatId, UserId); |
| UNBANCATMEMBER | Unban um membro do bate -papo. | UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId); |
| CreateChatinvitelink | Crie um link de convite de bate -papo. | InviteLink := TelegramBot.CreateChatInviteLink(ChatId); |
| Revokechatinvitelink | Revogar um link de convite de bate -papo. | RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, 'your_invite_link'); |
| ExportchatinviteLink | Exportar um link de convite de bate -papo. | ExportedLink := TelegramBot.ExportChatInviteLink(ChatId); |
| AprovechatJoinRequest | Aprovar uma solicitação de junta de bate -papo. | Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId); |
| DeclineChatJoinRequest | Recusar uma solicitação de ingresso no bate -papo. | Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId); |
| DeleteChatphoto | Exclua a foto de bate -papo. | PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId); |
| SetChattitle | Defina o título do bate -papo. | TitleSet := TelegramBot.SetChatTitle(ChatId, 'New Title'); |
| SetChatDescription | Defina a descrição do chat. | DescriptionSet := TelegramBot.SetChatDescription(ChatId, 'New Description'); |
| Levechat | Deixe o chat. | LeftChat := TelegramBot.LeaveChat(ChatId); |
| Getchat | Obtenha informações sobre o bate -papo. | ChatInfo := TelegramBot.GetChat(ChatId); |
| SetMyname | Defina o nome do bot. | NameSet := TelegramBot.SetMyName('New Bot Name'); |
| GetMyname | Obtenha o nome do bot. | BotName := TelegramBot.GetMyName(); |
| SetMyDescription | Defina a descrição do bot. | DescriptionSet := TelegramBot.SetMyDescription('New Bot Description'); |
| GetMyDescription | Obtenha a descrição do bot. | BotDescription := TelegramBot.GetMyDescription(); |
| GeninlineKeyboard | Uma resposta teclados | Response := TelegramBot.GenInlineKeyBoard(AButtonList,NumberOfButtonPerRow); |
Você precisa criar um bot antes de usar este componente.
Para o canal público, é super fácil de encontrar seu chatid.
Ex : https://t.me/abcdefg - > ChatId := @abcdefg;Obtenha informações sobre o bot.
var BotInfo := TelegramBot.GetMe;Faça logon no bot.
var LoggedOut := TelegramBot.LogOut;Feche a conexão bot.
var Closed := TelegramBot.Close;Envie uma mensagem de texto.
var Message := TelegramBot.SendMessage(ChatId, ' Hello, Telegram! ' );Encaminhar uma mensagem.
var ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId);Copie uma mensagem.
var CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId);Envie uma 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);Envie um arquivo de áudio.
var AudioMessage := TelegramBot.SendAudio(ChatId, ' path/to/audio.mp3 ' , ' Listen to this! ' );Envie um documento.
var DocumentMessage := TelegramBot.SendDocument(ChatId, ' path/to/document.pdf ' );Envie um vídeo.
var VideoMessage := TelegramBot.SendVideo(ChatId, ' path/to/video.mp4 ' );Envie uma animação (GIF).
var AnimationMessage := TelegramBot.SendAnimation(ChatId, ' path/to/animation.gif ' );Envie uma mensagem de voz.
var VoiceMessage := TelegramBot.SendVoice(ChatId, ' path/to/voice.ogg ' );Envie uma nota de vídeo.
var VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, ' path/to/videonote.mp4 ' );Envie um local.
var LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude);Envie um local.
var VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, ' Venue Title ' , ' Venue Address ' );Envie um contato.
var ContactMessage := TelegramBot.SendContact(ChatId, ' 123456789 ' , ' John Doe ' );Envie uma pesquisa.
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);Envie um dado.
MyEmoji := TEmojiDice.Basketball;
var DiceMessage := TelegramBot.SendDice(ChatId, MyEmoji);Obtenha atualizações do servidor.
// By Default : Limit = 100; OffSet = -1; TimeOut = 0
var Updates := TelegramBot.GetUpdates(limit,AOffSet,ATimeOut);
Obtenha informações sobre um arquivo.
var FileInfo := TelegramBot.GetFile(FileId);Banir um membro do bate -papo.
var Banned := TelegramBot.BanChatMember(ChatId, UserId);Unban um membro do bate -papo.
var UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId);Crie um link de convite de bate -papo.
var InviteLink := TelegramBot.CreateChatInviteLink(ChatId);Revogar um link de convite de bate -papo.
var RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, ' your_invite_link ' );Exportar um link de convite de bate -papo.
var ExportedLink := TelegramBot.ExportChatInviteLink(ChatId);Aprovar uma solicitação de junta de bate -papo.
var Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId);Recusar uma solicitação de ingresso no bate -papo.
var Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId);Exclua a foto de bate -papo.
var PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId);Defina o título do bate -papo.
var TitleSet := TelegramBot.SetChatTitle(ChatId, ' New Title ' );Defina a descrição do chat.
var DescriptionSet := TelegramBot.SetChatDescription(ChatId, ' New Description ' );Deixe o chat.
var LeftChat := TelegramBot.LeaveChat(ChatId);Obtenha informações sobre o bate -papo.
var ChatInfo := TelegramBot.GetChat(ChatId);Defina o nome do bot.
var NameSet := TelegramBot.SetMyName( ' New Bot Name ' );Obtenha o nome do bot.
var BotName := TelegramBot.GetMyName();Defina a descrição do bot.
var DescriptionSet := TelegramBot.SetMyDescription( ' New Bot Description ' );Obtenha a descrição do bot.
var BotDescription := TelegramBot.GetMyDescription();Habilite teclados embutidos para ações interativas. Os teclados embutidos suportam botões que podem funcionar nos bastidores ou abrir diferentes interfaces, incluindo botões URL.
Usando o temojiconstants precisa de uma unidade de terceira parte 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 é lançada sob a licença do MIT.
Sinta -se à vontade para contribuir, abrir problemas ou fornecer feedback!