I'm writing a telegram bot as a tool for technical support people. The main task is for the user to write his question to the bot, the bot forwards the question to the technical support chat, the technical support specialist gives an answer, and the bot forwards this answer back to the user. I wrote similar code using telegram api, spring and java.
And the bot does what it needs to do, but not correctly. Apparently, it forwards the answer only to me and other people from the technical support chat, but not to the outside user who contacted the bot. I asked the Bing neural network several times to see how it does it.
I present the program code below....
I assumed that the problem was incorrect processing within the incoming ID method(message ID, from chat id, user id...). I made changes to the methods that are responsible for forwarding a message to the chat from the user, and a response from the chat to the user, but to no avail
My application class
@SpringBootApplication
public class HeadFeedBack {
public static void main(String[] args) {
SpringApplication. run(HeadFeedBack.class, args);
}
}
Method for sending a chat message from a user
private void forwardMessageToSupportChat(Message message) {
SendMessage sendMessage = new SendMessage();
sendMessage.setChatId(SUPPORT_CHAT_ID);
sendMessage.setText("Message from user " + message.getFrom().getUserName() + ": " + message.getText());
try {
execute(sendMessage);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
Method responsible for responding to a user message (
@PostMapping("/forwardResponse")
public void forwardResponseFromTechSupport(@RequestBody String response, long userId) {
SendMessage sendMessage = new SendMessage();
sendMessage.setChatId(String.valueOf(userId));
sendMessage.setText(response);
try {
execute(sendMessage);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
Event handling method
@SneakyThrows
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
forwardMessageToSupportChat(update.getMessage());
sendResponseToUser(update.getMessage()); <---"notifying the user that his message has been sent"
}
}
I can show you the entire code if the need arises.
Please help me because I'm confused.