tinjecttelegram_delphi icon indicating copy to clipboard operation
tinjecttelegram_delphi copied to clipboard

Bug in TInjectTelegramBot.CopyMessage

Open DelphiMan68 opened this issue 2 years ago • 1 comments

Hello Sir, When I try to use CopyMessage, the Execute command returns a Json value in the form of {"message_id":14} and naturally it cannot convert it to Int64 and an error occurs. To temporarily solve this problem, I have changed the TInjectTelegramBot.CopyMessage method located in the TInjectTelegram.Bot.Impl unit to the following form and decided to inform you about this bug.

function TInjectTelegramBot.CopyMessage(const ChatId, FromChatId: TtdUserLink; const MessageId: Int64; const Caption: string; const ParseMode: TtdParseMode; const CaptionEntities: TArray<TtdMessageEntity>; const DisableWebPagePreview, DisableNotification: Boolean; const ReplyToMessageId: Int64; const AllowSendingWithoutReply: Boolean; ReplyMarkup: IReplyMarkup; const ProtectContent: Boolean): Int64; Var LTmpJson: String; LJsonResult : string; LJsonObj : TJsonObject; begin Logger.Enter(Self, 'CopyMessage'); LTmpJson := TJsonUtils.ArrayToJString<TtdMessageEntity>(CaptionEntities); LJsonResult := GetRequest.SetMethod('copyMessage') // .AddParameter('chat_id', ChatId, 0, True) // .AddParameter('from_chat_id', FromChatId, 0, True) // .AddParameter('message_id', MessageId, 0, True) // .AddParameter('caption', Caption, '', False) // .AddParameter('parse_mode', ParseMode.ToString, '', False) // .AddParameter('caption_entities', LTmpJson, '', False) // .AddParameter('disable_web_page_preview', DisableWebPagePreview, False, False) // .AddParameter('disable_notification', DisableNotification, False, False) // .AddParameter('reply_to_message_id', ReplyToMessageId, 0, False) // .AddParameter('allow_sending_without_reply', AllowSendingWithoutReply, False, False) // .AddParameter('protect_content ', ProtectContent, False, False) // .AddParameter('reply_markup', TInterfacedObject(ReplyMarkup), nil, False) // .Execute; // {"message_id":14} LJsonObj := TJSONObject.ParseJSONValue(LJsonResult) As TJSONObject; try Result := LJsonObj.GetValue<Int64>('message_id'); finally LJsonObj.Free end; Logger.Leave(Self, 'CopyMessage'); end;

DelphiMan68 avatar Sep 13 '23 09:09 DelphiMan68

Thank you for letting me know, I will do the necessary tests and correct this error.

dieletro avatar Sep 13 '23 10:09 dieletro