This demo shows how connect to Telegram, receive all contacts, send Text messages, send Images... and much more
sgcTelegram.Telegram.API.ApiHash := txtApiHash.Text;
sgcTelegram.Telegram.API.ApiId := txtApiId.Text;
sgcTelegram.Telegram.PhoneNumber := '';
sgcTelegram.Telegram.BotToken := '';
if chkLoginBot.Checked then
sgcTelegram.Telegram.BotToken := txtBotToken.Text
else
sgcTelegram.Telegram.PhoneNumber := txtPhoneNumber.Text;
sgcTelegram.Active := True;
procedure TFRMSGCTelegram.sgcTelegramAuthenticationCode(Sender: TObject;
var Code: string);
begin
Code := InputBox('Telegram', 'Introduce Telegram Code', '');
end;
To send a telegram message (text, files, images...) always requires first set the ChaId where you want to send the message and then the parameter that can be a text message, a filename...
// send text message
sgcTelegram.SendTextMessage('456413', 'Hello From sgcWebSockets!!!');
// send file message
sgcTelegram.SendDocumentMessage('383784', 'c:\yourfile.txt');
Messages received by Telegram client, are handled on specific event Handlers. There is an event when a next Text Message is received, when a new Document is received, photo...
procedure TFRMSGCTelegram.sgcTelegramMessageText(Sender: TObject;
MessageText: TsgcTelegramMessageText);
begin
DoLogMessage(MessageText.ChatId, IntToStr(MessageText.SenderUserId),
MessageText.Text);
end;
procedure TFRMSGCTelegram.sgcTelegramMessageDocument(Sender: TObject;
MessageDocument: TsgcTelegramMessageDocument);
begin
DoLogMessage(MessageDocument.ChatId, IntToStr(MessageDocument.SenderUserId),
'New Document: ' + MessageDocument.FileName);
end;