procedure TTGMBot.btn2Click(Sender: TObject);
// uses
// System.SysUtils,
// System.Classes,
// System.JSON.Types,
// System.JSON.Writers,
// System.JSON.Builders;
var
LIdHTTP: TIdHTTP;
LsList: TStringList;
LSr : TStringReader;
LReader : TJsonTextReader;
LBuilder: TJSONObjectBuilder;
LWriter: TJsonTextWriter;
LStringWriter: TStringWriter;
LStringBuilder: TStringBuilder;
const
command = '
/sendMessage';
text = '
text=test' ;
chat_id = '
chat_id=-xxxxxxx';
// Chat Id des destination Chat
LBotApiKey = '
64444444:AAxxxxxxxxxxxx_xxxxxxxxxxxxxx';
begin
LStringBuilder := TStringBuilder.Create;
try
LStringWriter := TStringWriter.Create(LStringBuilder);
try
LWriter := TJsonTextWriter.Create(LStringWriter);
try
LBuilder := TJSONObjectBuilder.Create(LWriter);
try
LsList := TStringList.Create;
try
LsList.DefaultEncoding.UTF8;
LsList.Add(chat_id) ;
LsList.Add(text) ;
LBuilder
.BeginObject
.BeginArray('
inline_keyboard')
.BeginArray()
.BeginObject
.Add('
text', '
Yes')
.Add('
url', '
http://www.google.com/')
.EndObject
.BeginObject
.Add('
text', '
no')
.Add('
url', '
https://www.bing.com/')
.EndObject
.EndArray
.EndArray
.EndObject;
LsList.Add('
reply_markup=' + LStringBuilder.ToString) ;
LIdHTTP:= TIdHTTP.Create();
try
mm2(LIdHTTP.post('
https://api.telegram.org/bot' + LBotApiKey + command ,LsList));
finally
LIdHTTP.Free;
end;
LWriter.Formatting := TJsonFormatting.Indented;
mm2(LStringBuilder.ToString);
// mm2 = TMemo
finally
LsList.Free;
end;
finally
LBuilder.Free;
end;
finally
LWriter.Free;
end;
finally
LStringWriter.Free;
end;
finally
LStringBuilder.Free;
end;
end;