DTelegram
1.0.0

這是用於與Telegram Bot API交互的Delphi組件。它提供了一組功能,可以使用Telegram Bot平台執行各種操作。
要在Delphi項目中使用此組件,請按照以下步驟:
DTelegram.dproj文件。DTelegram.bpl 。此步驟可能涉及右鍵單擊項目文件,然後選擇“編譯”,然後選擇“安裝”。 | 功能 | 描述 | 示例用法 |
|---|---|---|
| Getme | 獲取有關機器人的信息。 | BotInfo := TelegramBot.GetMe; |
| 註銷 | 從機器人登錄。 | LoggedOut := TelegramBot.LogOut; |
| 關閉 | 關閉機器人連接。 | Closed := TelegramBot.Close; |
| sendmessage | 傳簡訊. | Message := TelegramBot.SendMessage(ChatId, 'Hello, Telegram!'); |
| 遠前 | 轉發一條消息。 | ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId); |
| 共同主題 | 複製一條消息。 | CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId); |
| sendphoto | 發送照片。 | PhotoMessage := TelegramBot.SendPhoto(ChatId, 'path/to/photo.jpg', 'Check this out!'); |
| sendaudio | 發送音頻文件。 | AudioMessage := TelegramBot.SendAudio(ChatId, 'path/to/audio.mp3', 'Listen to this!'); |
| senddocument | 發送文件。 | DocumentMessage := TelegramBot.SendDocument(ChatId, 'path/to/document.pdf'); |
| sendvideo | 發送視頻。 | VideoMessage := TelegramBot.SendVideo(ChatId, 'path/to/video.mp4'); |
| sendAnimation | 發送動畫(GIF)。 | AnimationMessage := TelegramBot.SendAnimation(ChatId, 'path/to/animation.gif'); |
| sendvoice | 發送語音消息。 | VoiceMessage := TelegramBot.SendVoice(ChatId, 'path/to/voice.ogg'); |
| sendVideOnote | 發送視頻筆記。 | VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, 'path/to/videonote.mp4'); |
| 發送定位 | 發送位置。 | LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude); |
| 發送 | 發送一個場地。 | VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, 'Venue Title', 'Venue Address'); |
| sendContact | 發送聯繫人。 | ContactMessage := TelegramBot.SendContact(ChatId, '123456789', 'John Doe'); |
| sendpoll | 發送民意調查。 | PollMessage := TelegramBot.SendPoll(ChatId, 'Which is your favorite color?', ['Red', 'Green', 'Blue']); |
| senddice | 發送骰子。 | DiceMessage := TelegramBot.SendDice(ChatId, '?'); |
| getupdates | 從服務器獲取更新。 | Updates := TelegramBot.GetUpdates(100, -1, 0); |
| getfile | 獲取有關文件的信息。 | FileInfo := TelegramBot.GetFile(FileId); |
| Banchatmember | 禁止聊天會員。 | Banned := TelegramBot.BanChatMember(ChatId, UserId); |
| Unbanchatmember | 取消聊天會員。 | UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId); |
| CreateChatinVitelink | 創建聊天邀請鏈接。 | InviteLink := TelegramBot.CreateChatInviteLink(ChatId); |
| RevokeChatinVitelink | 撤銷聊天邀請鏈接。 | RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, 'your_invite_link'); |
| ExportChatinVitelink | 導出聊天邀請鏈接。 | ExportedLink := TelegramBot.ExportChatInviteLink(ChatId); |
| Applovechatjoinrequest | 批准聊天加入請求。 | Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId); |
| Declinechatjoinrequest | 拒絕聊天加入請求。 | Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId); |
| Deletechatphoto | 刪除聊天照片。 | PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId); |
| setchattitle | 設置聊天標題。 | TitleSet := TelegramBot.SetChatTitle(ChatId, 'New Title'); |
| setChatDescription | 設置聊天描述。 | DescriptionSet := TelegramBot.SetChatDescription(ChatId, 'New Description'); |
| Leavechat | 離開聊天。 | LeftChat := TelegramBot.LeaveChat(ChatId); |
| Getchat | 獲取有關聊天的信息。 | ChatInfo := TelegramBot.GetChat(ChatId); |
| setMyname | 設置機器人的名字。 | NameSet := TelegramBot.SetMyName('New Bot Name'); |
| getMyname | 獲取機器人的名字。 | BotName := TelegramBot.GetMyName(); |
| setMyDescription | 設置機器人的描述。 | DescriptionSet := TelegramBot.SetMyDescription('New Bot Description'); |
| getMyDescription | 獲取機器人的描述。 | BotDescription := TelegramBot.GetMyDescription(); |
| GeninlineKeyboard | 回复鍵盤 | Response := TelegramBot.GenInlineKeyBoard(AButtonList,NumberOfButtonPerRow); |
在使用此組件之前,您需要創建一個機器人。
因為公共頻道非常容易找到其chatid。
Ex : https://t.me/abcdefg - > ChatId := @abcdefg;獲取有關機器人的信息。
var BotInfo := TelegramBot.GetMe;從機器人登錄。
var LoggedOut := TelegramBot.LogOut;關閉機器人連接。
var Closed := TelegramBot.Close;傳簡訊.
var Message := TelegramBot.SendMessage(ChatId, ' Hello, Telegram! ' );轉發一條消息。
var ForwardedMessage := TelegramBot.ForwardMessage(TargetChatId, SourceChatId, MessageId);複製一條消息。
var CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId);發送照片。
// 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);發送音頻文件。
var AudioMessage := TelegramBot.SendAudio(ChatId, ' path/to/audio.mp3 ' , ' Listen to this! ' );發送文件。
var DocumentMessage := TelegramBot.SendDocument(ChatId, ' path/to/document.pdf ' );發送視頻。
var VideoMessage := TelegramBot.SendVideo(ChatId, ' path/to/video.mp4 ' );發送動畫(GIF)。
var AnimationMessage := TelegramBot.SendAnimation(ChatId, ' path/to/animation.gif ' );發送語音消息。
var VoiceMessage := TelegramBot.SendVoice(ChatId, ' path/to/voice.ogg ' );發送視頻筆記。
var VideoNoteMessage := TelegramBot.SendVideoNote(ChatId, ' path/to/videonote.mp4 ' );發送位置。
var LocationMessage := TelegramBot.SendLocation(ChatId, Latitude, Longitude);發送一個場地。
var VenueMessage := TelegramBot.SendVenue(ChatId, Latitude, Longitude, ' Venue Title ' , ' Venue Address ' );發送聯繫人。
var ContactMessage := TelegramBot.SendContact(ChatId, ' 123456789 ' , ' John Doe ' );發送民意調查。
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);發送骰子。
MyEmoji := TEmojiDice.Basketball;
var DiceMessage := TelegramBot.SendDice(ChatId, MyEmoji);從服務器獲取更新。
// By Default : Limit = 100; OffSet = -1; TimeOut = 0
var Updates := TelegramBot.GetUpdates(limit,AOffSet,ATimeOut);
獲取有關文件的信息。
var FileInfo := TelegramBot.GetFile(FileId);禁止聊天會員。
var Banned := TelegramBot.BanChatMember(ChatId, UserId);取消聊天會員。
var UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId);創建聊天邀請鏈接。
var InviteLink := TelegramBot.CreateChatInviteLink(ChatId);撤銷聊天邀請鏈接。
var RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, ' your_invite_link ' );導出聊天邀請鏈接。
var ExportedLink := TelegramBot.ExportChatInviteLink(ChatId);批准聊天加入請求。
var Approved := TelegramBot.ApproveChatJoinRequest(ChatId, UserId);拒絕聊天加入請求。
var Declined := TelegramBot.DeclineChatJoinRequest(ChatId, UserId);刪除聊天照片。
var PhotoDeleted := TelegramBot.DeleteChatPhoto(ChatId);設置聊天標題。
var TitleSet := TelegramBot.SetChatTitle(ChatId, ' New Title ' );設置聊天描述。
var DescriptionSet := TelegramBot.SetChatDescription(ChatId, ' New Description ' );離開聊天。
var LeftChat := TelegramBot.LeaveChat(ChatId);獲取有關聊天的信息。
var ChatInfo := TelegramBot.GetChat(ChatId);設置機器人的名字。
var NameSet := TelegramBot.SetMyName( ' New Bot Name ' );獲取機器人的名字。
var BotName := TelegramBot.GetMyName();設置機器人的描述。
var DescriptionSet := TelegramBot.SetMyDescription( ' New Bot Description ' );獲取機器人的描述。
var BotDescription := TelegramBot.GetMyDescription();啟用內聯鍵盤進行交互式操作。內聯鍵盤支持可以在幕後工作或打開不同接口(包括URL按鈕)的按鈕。
使用temojiconstants需要第三部分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 ;該庫是根據麻省理工學院許可證發布的。
隨時貢獻,打開問題或提供反饋!