Skip to content

Commit

Permalink
Fix force setting of the message parsing method (#28)
Browse files Browse the repository at this point in the history
* fix: make force setting of the message parsing method only if AbstractTelegramResponse parsing method is "NO"

Previously, if you set setParseMode({value}) for GenericTelegramResponse, set {value} was ignored
  • Loading branch information
elisevgeniy authored Jan 8, 2025
1 parent df3b833 commit f626f92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ private void doAnswer(DefaultUpdateRequest request) throws TelegramApiException
simpleMessageTelegramResponse.setMessageSource(messageSource);
}
if (response instanceof AbstractTelegramResponse abstractTelegramResponse) {
abstractTelegramResponse.setParseMode(
telegramProperties.getUpdateHandler().getParseMode());
if (abstractTelegramResponse.getParseMode() == null) {
abstractTelegramResponse.setParseMode(
telegramProperties.getUpdateHandler().getParseMode()
);
}
}
response.process(request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.drednote.telegram.core.request.UpdateRequest;
import io.github.drednote.telegram.handler.UpdateHandlerProperties.ParseMode;
import org.springframework.lang.Nullable;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.message.Message;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
Expand All @@ -14,7 +15,8 @@
*/
public abstract class AbstractTelegramResponse implements TelegramResponse {

protected ParseMode parseMode = ParseMode.NO;
@Nullable
protected ParseMode parseMode = null;

/**
* Sends a text message to the specified chat using the provided string
Expand All @@ -29,11 +31,18 @@ protected Message sendString(String string, UpdateRequest request)
TelegramClient absSender = request.getAbsSender();
Long chatId = request.getChatId();
SendMessage sendMessage = new SendMessage(chatId.toString(), string);
sendMessage.setParseMode(parseMode.getValue());
if (parseMode != null) {
sendMessage.setParseMode(parseMode.getValue());
}
return absSender.execute(sendMessage);
}

public void setParseMode(ParseMode parseMode) {
this.parseMode = parseMode;
}

@Nullable
public ParseMode getParseMode() {
return parseMode;
}
}

0 comments on commit f626f92

Please sign in to comment.