
นี่คือองค์ประกอบ Delphi สำหรับการโต้ตอบกับ Telegram Bot API มันมีชุดของฟังก์ชั่นเพื่อดำเนินการต่าง ๆ โดยใช้แพลตฟอร์ม 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); |
| copymessage | คัดลอกข้อความ | CopiedMessageId := TelegramBot.CopyMessage(TargetChatId, SourceChatId, MessageId); |
| sendphoto | ส่งรูปถ่าย | PhotoMessage := TelegramBot.SendPhoto(ChatId, 'path/to/photo.jpg', 'Check this out!'); |
| ผู้ส่ง | ส่งไฟล์เสียง | 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'); |
| การอนิป | ส่งแอนิเมชั่น (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']); |
| ผู้ส่ง | ส่งลูกเต๋า | DiceMessage := TelegramBot.SendDice(ChatId, '?'); |
| getUpdates | รับการอัปเดตจากเซิร์ฟเวอร์ | Updates := TelegramBot.GetUpdates(100, -1, 0); |
| GetFile | รับข้อมูลเกี่ยวกับไฟล์ | FileInfo := TelegramBot.GetFile(FileId); |
| Banchatmember | ห้ามสมาชิกแชท | Banned := TelegramBot.BanChatMember(ChatId, UserId); |
| uncanchatmember | ปลดสมาชิกแชท | UnBanned := TelegramBot.UnBanChatMember(ChatId, UserId); |
| createchatinvitelink | สร้างลิงค์เชิญแชท | InviteLink := TelegramBot.CreateChatInviteLink(ChatId); |
| revokechatinvitelink | เพิกถอนลิงค์เชิญแชท | RevokedLink := TelegramBot.RevokeChatInviteLink(ChatId, 'your_invite_link'); |
| ExportChatinVitelink | ส่งออกลิงค์เชิญแชท | ExportedLink := TelegramBot.ExportChatInviteLink(ChatId); |
| Approechatjoinrequest | อนุมัติคำขอเข้าร่วมแชท | 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'); |
| กระวาน | ออกจากการแชท | 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); |
คุณต้องสร้างบอทก่อนที่จะใช้ส่วนประกอบนี้
สำหรับช่องสาธารณะนั้นง่ายมากที่จะค้นหาแชท
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 ;ห้องสมุดนี้เปิดตัวภายใต้ใบอนุญาต MIT
อย่าลังเลที่จะมีส่วนร่วมเปิดปัญหาหรือให้ข้อเสนอแนะ!