You must implement a subscription to the daily weather forecast. There is no way to "capture" the parameters for the current location with the "/ subscribe" command.
Here is a piece of code:
public class Bot extends TelegramLongPollingBot { public void onUpdateReceived(Update update) { if (update.hasMessage()) { String command = update.getMessage().getText(); Message message = update.getMessage(); long chat_id = update.getMessage().getChatId(); Float latitude = message.getLocation().getLatitude(); Float longitude = message.getLocation().getLongitude(); if (message.hasLocation()) { SendMessage sendMessage = new SendMessage(); String weatherResponse = ""; //текущая погода try { weatherResponse = Weather.getInstance().currentWeather(latitude, longitude); } catch (IOException e) { e.printStackTrace(); } sendMessage.setText(weatherResponse); sendMessage.setChatId(chat_id); try { execute(sendMessage); } catch (TelegramApiException e) { e.printStackTrace(); } //прогноз погоды на ближайшие сутки try { weatherResponse = Weather.getInstance().forecastWeather(latitude, longitude); } catch (IOException e) { e.printStackTrace(); } sendMessage.setText(weatherResponse).setChatId(chat_id); try { execute(sendMessage); } catch (TelegramApiException e) { e.printStackTrace(); } }else if (command.equals("/subscribe")) { // подписка на прогноз погоды Database database = new Database(); try { database.WriteDB(message.getChatId(), message.getChat().getUserName(), message.getChat().getFirstName(), message.getChat().getLastName(), message.getLocation().getLatitude(), //здесь значение параметра равно NULL message.getLocation().getLongitude()); //здесь значение параметра равно NULL } catch (SQLException e) { e.printStackTrace(); } SendMessage sendMsg = new SendMessage(); sendMsg.setChatId(chat_id).setText("Thanks for subscribe!!!"); try { execute(sendMsg); } catch (TelegramApiException e) { e.printStackTrace(); } try { execute(sendMsg); } catch (TelegramApiException e) { e.printStackTrace(); } } else if (command.equals("/unsubscribe")) { // отписка от прогноза погоды } } }.................... I can not figure out how to implement the connection between sending the current location and the subscription command ("/ subscribe").
@Scheduled- iksuyKeyboardButtonyou need to setrequestLocationtotrue. - iksuy