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 ;该库是根据麻省理工学院许可证发布的。
随时贡献,打开问题或提供反馈!