I am having an issue with the encoding of the message to be sent to a Telegram bot. Im using a Quarkus/Java project with Apache Camel The input is like this:
localhost:8084/enviarTelegram?id=1111111111&mensagem=mas olha só que belezinha
And the code is like this:
@Override
public void configure() {
rest("/enviarTelegram")
.get()
.param().name("id").type(RestParamType.query).endParam()
.param().name("mensagem").type(RestParamType.query).endParam()
.to("direct:send-message-to-user");
from("direct:send-message-to-user")
.log("Recebendo solicitação para enviar mensagem para ID: ${header.id}")
.choice()
.when(header("id").isNotNull()
)
.log("Sending message to user with ID: ${header.id}")
.setHeader("chatId", simple("${header.id}"))
.setBody(simple("${header.mensagem}"))
.toD("telegram:bots?authorizationToken=" + token + "&chatId=${header.id}")
.convertBodyTo(String.class)
.otherwise()
.log("ERRO: Nenhum ID foi recebido!")
.stop()
.end();
tryed to set head encode:
.setHeader(Exchange.CONTENT_ENCODING, simple("charset=UTF-8"))
.setHeader("Content-Type", simple("application/json; charset=UTF-8"))
Tryed to process before set:
.process(exchange -> {
String mensagem = exchange.getIn().getBody(String.class);
if (mensagem != null) {
exchange.getIn().setBody(new String(mensagem.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
}
})
Im getting messenger like that:
mas olha s? que belezinha
Expecting to get like that: mas olha só que belezinha