
これは、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!'); |
| ForwardMessage | メッセージを転送します。 | 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'); |
| sendlocation | 場所を送信します。 | 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']); |
| 送信 | サイコロを送ってください。 | DiceMessage := TelegramBot.SendDice(ChatId, '?'); |
| getUpdates | サーバーから更新を取得します。 | Updates := TelegramBot.GetUpdates(100, -1, 0); |
| getFile | ファイルに関する情報を取得します。 | FileInfo := TelegramBot.GetFile(FileId); |
| バンチャットメンバー | チャットメンバーを禁止します。 | Banned := TelegramBot.BanChatMember(ChatId, UserId); |
| banchatmember | チャットメンバーをアンバン。 | UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId); |
| createchatinvitelink | チャットInviteリンクを作成します。 | InviteLink := TelegramBot.CreateChatInviteLink(ChatId); |
| Revokechatinvitelink | チャット招待リンクを取り消します。 | RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, 'your_invite_link'); |
| exportchatinvitelink | チャット招待リンクをエクスポートします。 | ExportedLink := TelegramBot.ExportChatInviteLink(ChatId); |
| applevechatjoinrequest | チャット参加リクエストを承認します。 | 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);チャットInviteリンクを作成します。
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を使用するには、第3部ユニット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 ;このライブラリはMITライセンスの下でリリースされます。
自由に貢献したり、問題を開いたり、フィードバックを提供したりしてください!