Closed solomode0001 closed 6 months ago
Because you incorrectly use InputMessageReplyToMessage
. See documentation of the chat_id
field:
The identifier of the chat to which the message to be replied belongs; pass 0 if the message to be replied is in the same chat. Must always be 0 for replies in secret chats. A message can be replied in another chat or topic only if message.can_be_replied_in_another_chat
Could you fix my code so it can properly reply to messages?
private static void ReplyToMessage(long chatId, long messageIdToReply, string replyText)
{
InputMessageContent messageContent = new TdApi.InputMessageText(new TdApi.FormattedText(replyText, null), null, true);
InputMessageReplyTo replyTo = new InputMessageReplyToMessage(chatId, messageIdToReply, null);
SendMessage sendMessageRequest = new TdApi.SendMessage(chatId, 0, replyTo, null, null, messageContent);
_client.Send(sendMessageRequest, _defaultHandler);
}
private class UpdateHandler : Td.ClientResultHandler
{
void Td.ClientResultHandler.OnResult(TdApi.BaseObject @object)
{
if (@object is TdApi.UpdateAuthorizationState)
{
OnAuthorizationStateUpdated((@object as TdApi.UpdateAuthorizationState).AuthorizationState);
}
else
{
// Print("Unsupported update: " + @object);
if (@object is TdApi.UpdateNewMessage updateNewMessage)
{
Print(@object.ToString());
TdApi.MessageContent content = updateNewMessage.Message.Content;
if (content is TdApi.MessageText text)
{
string message = text.Text.Text;
long chatId = updateNewMessage.Message.ChatId;
long messageId = updateNewMessage.Message.Id;
// Print($"message = {message} :: chat_id = {chatId} :: message_id = {messageId} :: message_length = {message.Length}");
if (message.ToLower().Contains("Hello"))
{
ReplyToMessage(chatId, messageId, "Wellcome!");
}
}
}
}
}
}
I have found the solution.
I am trying to create a function that can reply to messages using a C# program.
In the updateNewMessage function, there is a difference between the messages being replied to in my program and manually.
The difference lies in the reply_to:
This is the manual reply log:
And this is from my code:
Why are chat_id and message_id 0?
Full log manual:
Full log program: