Skip to content

Commit

Permalink
New: getChatMember, Fixed: photo's caption
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Muhandis committed Jul 7, 2019
1 parent 10a43b3 commit ec4dab3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions test/testbase.pas
Expand Up @@ -28,11 +28,13 @@ TTestTelegramClass= class(TTestTelegramBase)
private
FBot: TTelegramSender;
FChatID: Int64;
FUserID: Integer;
protected
procedure SetUp; override;
procedure TearDown; override;
property Bot: TTelegramSender read FBot;
property ChatID: Int64 read FChatID;
property UserID: Integer read FUserID;
end;

implementation
Expand All @@ -48,6 +50,7 @@ procedure TTestTelegramClass.SetUp;
FChatID:=Conf.ReadInt64('Chat', 'ID', 0);
if FChatID=0 then
Fail('Please, specify chat ID in testtelegram.ini! See readme.md');
FUserID:=Conf.ReadInteger('User', 'ID', 0);
end;

procedure TTestTelegramClass.TearDown;
Expand Down
10 changes: 10 additions & 0 deletions test/testtelegram.pas
Expand Up @@ -22,6 +22,7 @@ TTestSender= class(TTestTelegramClass)
procedure sendMessage;
procedure InlineKeyboard;
procedure sendVideo;
procedure ChatMember;
end;

{ TTestSenderProcedure }
Expand Down Expand Up @@ -236,6 +237,15 @@ procedure TTestSender.sendVideo;
'. Description: '+Bot.LastErrorDescription);
end;

procedure TTestSender.ChatMember;
begin
Bot.getChatMember(ChatID, UserID);
SaveJSONData(Bot.JSONResponse, '~responce.json');
if Bot.LastErrorCode<>0 then
Fail('Error from telegram API server. Error code: '+IntToStr(Bot.LastErrorCode)+
'. Description: '+Bot.LastErrorDescription);
end;

initialization

RegisterTests([TTestSender, TTestSenderProcedure, TTestReceiveLongPolling, TTestPayments]);
Expand Down
22 changes: 21 additions & 1 deletion tgsendertypes.pas
Expand Up @@ -464,6 +464,7 @@ TTelegramSender = class
inline_message_id: String = ''; ReplyMarkup: TReplyMarkup = nil): Boolean;
function editMessageText(const AMessage: String; ParseMode: TParseMode = pmDefault;
DisableWebPagePreview: Boolean=False; ReplyMarkup: TReplyMarkup = nil): Boolean; overload;
function getChatMember(chat_id: Int64; user_id: Integer): Boolean;
function getMe: Boolean;
function getUpdates(offset: Int64 = 0; limit: Integer = 0; timeout: Integer = 0;
allowed_updates: TUpdateSet = []): Boolean;
Expand Down Expand Up @@ -608,6 +609,7 @@ implementation
s_sendMediaGroup='sendMediaGroup';
s_getUpdates='getUpdates';
s_getMe='getMe';
s_getChatMember='getChatMember';
s_answerInlineQuery='answerInlineQuery';
s_answerPreCheckoutQuery='answerPreCheckoutQuery';
s_deleteMessage='deleteMessage';
Expand All @@ -617,6 +619,7 @@ implementation
s_Url = 'url';
s_Text = 'text';
s_ChatId = 'chat_id';
s_UserID = 'user_id';
s_MessageId = 'message_id';
s_InlineMessageId = 'inline_message_id';
s_Document = 'document';
Expand Down Expand Up @@ -2293,6 +2296,23 @@ function TTelegramSender.editMessageText(const AMessage: String;
Result:=sendMessage(AMessage, ParseMode, DisableWebPagePreview, ReplyMarkup);
end;

function TTelegramSender.getChatMember(chat_id: Int64; user_id: Integer
): Boolean;
var
sendObj: TJSONObject;
begin
Result:=False;
sendObj:=TJSONObject.Create;
with sendObj do
try
Add(s_ChatId, chat_id);
Add(s_UserID, user_id);
Result:=SendMethod(s_getChatMember, sendObj);
finally
Free;
end;
end;

function TTelegramSender.getMe: Boolean;
var
sendObj: TJSONObject;
Expand Down Expand Up @@ -2621,7 +2641,7 @@ function TTelegramSender.sendPhoto(chat_id: Int64; const APhoto: String;
try
Add(s_ChatId, chat_id);
Add(s_Photo, APhoto);
Add(s_Photo, ACaption);
Add(s_Caption, ACaption);
if ParseMode<>pmDefault then
Add(s_ParseMode, ParseModes[ParseMode]);
if Assigned(ReplyMarkup) then
Expand Down

0 comments on commit ec4dab3

Please sign in to comment.