Reputation: 518
I make a TelegramBot that is going to count my expanses, and one of its functions should be counting expenses for the specific period of time and showing these expenses. I use MySQL DB, so I am querying and it works, but sendMessage of TelegramAPI allows to send messages with the maximum length 4096UTF-8 characters, which may be not sufficient if i have big database. So how can I make the bot to send several messages? E.g.
public SendMessage onGetExpensesCommand(Message message, String[] dateFrames){
SendMessage returnMessage = new SendMessage();
returnMessage.setText(getExpensesFromDB(String[] dateFrames));//queries DB
returnMessage.setReplyToMessageId(message.getMessageId());
returnMessage.setChatId(message.getChatId().toString());
return returnMessage;
}
Later message is sent.
Upvotes: 0
Views: 1571
Reputation: 1700
i don't know java but i made a nice function for it in python. i build the message string. one the message string is finished, i create a list and i split that long message in many small (the maximum size allowed by telegram) messages and i add them inside the list.
At the end i run a for loop and i use sendMessage method to send all of them one by one. i add a time sleep between them to make sure not to hit telegram flood limits.
I store in a variable the first sent message, and once the loop is ended i send a message "click here to go to the first message" in reply to the first sent message.
the only difficult part of this is if you have to handle formatting too
Upvotes: 1