### Run the Bot (Java) Source: https://zoommax.github.io/OneMessageBot/quickstart This Java code snippet shows the process of running the OneMessageBot. It involves creating a BotApp instance with the previously configured BotSettings and starting it in a new thread. Ensure BotSettings are properly initialized before this step. ```java package test.cl; import space.zoommax.BotApp; public class Main { public static void main(String[] args) { //BotSettings botSettings = BotSettings.builder() // ... // .build(); new Thread(new BotApp(botSettings)).start(); } } ``` -------------------------------- ### Handle Telegram Bot Start Command and Messages in Java Source: https://zoommax.github.io/OneMessageBot/quickstart This Java snippet demonstrates how to handle the '/start' command and subsequent messages in a Telegram bot. It sets the user's language and constructs a text message with a custom keyboard containing links and action buttons. It also handles callback queries for specific button presses. ```java package test.cl; import com.pengrad.telegrambot.model.PhotoSize; import com.pengrad.telegrambot.model.Update; import space.zoommax.BotApp; import space.zoommax.utils.CreateNotification; import space.zoommax.utils.ViewMessageImpl; import space.zoommax.utils.db.NotificationType; import space.zoommax.utils.keyboard.Keyboard; import space.zoommax.view.TextMessage; import space.zoommax.view.ViewMessage; @ViewMessageListener public class Start implements ViewMessageImpl { @Override public ViewMessage onMessage(String message, int messageId, long chatId, String onMessageFlag, Update update) { if (onMessageFlag.equals("start")) { return TextMessage.builder() .onMessageFlag("start") .text("Hello " + message) .chatId(chatId) .keyboard(Keyboard.builder() .chatId(chatId) .code("{Google;https://google.com}{Yandex;https://ya.ru}\n" + "{Start;strt}\n" + "{Google;https://google.com}{Yandex;https://ya.ru}\n" + "{Start;strt}\n" + "{Google;https://google.com}{Yandex;https://ya.ru}\n" + "{Start;strt}\n" + "{Google;https://google.com}{Yandex;https://ya.ru}\n" + "{Start;strt}") .build()) .build(); } return null; } @Override public ViewMessage onCommand(String command, int messageId, long chatId, Update update) { if (command.equals("/start")) { if (chatId == 000000) { BotApp.setUserLanguage(String.valueOf(chatId), "default_en_US"); } return TextMessage.builder() .onMessageFlag("start") .text("Hello") .chatId(chatId) .keyboard(Keyboard.builder() .chatId(chatId) .code("{Google;https://google.com}{Yandex;https://ya.ru}\n" + "{Start;strt}") .build()) .build(); } return null; } @Override public ViewMessage onPicture(PhotoSize[] photoSize, String caption, int messageId, long chatId, Update update) { return null; } @Override public ViewMessage onCallbackQuery(String data, int messageId, long chatId, Update update) { if (data.equals("strt")) { CreateNotification createNotification = new CreateNotification("Hello callback notify", String.valueOf(chatId), null, NotificationType.FULL, null); createNotification.run(); try { Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } return TextMessage.builder() .onMessageFlag("start") .text("Hello callback") .chatId(chatId) .keyboard(Keyboard.builder() .chatId(chatId) .code("{Google;https://google.com}{Yandex;https://ya.ru}\n" + "{Start;strt}") .build()) .build(); } return null; } @Override public ViewMessage onInlineQuery(String query, String queryId, long chatId, Update update) { return null; } @Override public ViewMessage onChosenInlineResult(String resultId, long queryId, String chatId, Update update) { return null; } } ``` -------------------------------- ### Configure Bot Settings (Java) Source: https://zoommax.github.io/OneMessageBot/quickstart This Java code illustrates how to configure the settings for the OneMessageBot. It uses the BotSettings.builder() to set parameters like the bot token, database type, and language directory. This configuration is essential before running the bot. ```java package test.cl; import space.zoommax.BotSettings; import space.zoommax.utils.db.DbType; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { BotSettings botSettings = BotSettings.builder() .botToken("XXXX:yyyyyy") .dbType(DbType.SQLITE) .buttonsRows(5) .dbName("TestBotApp") .languageDirPath("translations") .defaultLanguage("my_default_lang") .dbConnection(null) .dbUrl("jdbc:sqlite:./") .dbUser("") .dbPassword("") .build(); } } ``` -------------------------------- ### Build and Send VideoMessage in Java Source: https://zoommax.github.io/OneMessageBot/viewmessage/videomessage This Java example demonstrates how to use the VideoMessage builder to construct a message for sending videos. It covers setting the video source via URL, chat ID, and an optional keyboard. The VideoMessage can then be sent using the run() method. Dependencies include the space.zoommax.view.VideoMessage class and potentially Keyboard. ```java import space.zoommax.view.VideoMessage; import java.io.File; public class example { public static void main(String[] args) { VideoMessage videoMessage = VideoMessage.builder() .chatId(123456789) .videoAsUrl("https://example.com/video.mp4") /*optional .videoAsFile(new File("path/to/video.mp4")) .videoAsBytes(new byte[]{1,2,3,4,5}) */ .keyboard(Keyboard.builder() .chatId(123456789) .code("{Google;https://google.ru}{Yandex;https://ya.ru}\n" + "{Start;strt}") .build()) .caption("Hello") .onMessageFlag("start") .notify(false) .build(); videoMessage.run(); } } ``` -------------------------------- ### Retrieve Translations Using LocalizationManager Source: https://zoommax.github.io/OneMessageBot/localization/localization Fetch translated strings for a given chat ID and localization key. This example demonstrates how to use the LocalizationManager to get bot messages, supporting dynamic language selection based on the user's saved language preference. Accesses nested keys using dot notation. ```java import space.zoommax.BotApp; import space.zoommax.utils.lang.LocalizationManager; import space.zoommax.utils.lang.UserLanguage; // Assuming UserLanguage is in this package LocalizationManager localizationManager = BotApp.localizationManager; String botStart = localizationManager.getTranslationForLanguage(UserLanguage.getUserLanguage(chatId), "main.bot_starting"); // botStart will contain the translated string for "main.bot_starting" for the user's language. ``` -------------------------------- ### Create and Send TextMessage with Keyboard (Java) Source: https://zoommax.github.io/OneMessageBot/viewmessage/textmessage Demonstrates how to use the TextMessage builder to construct a text message. It includes setting the message text, chat ID, a custom keyboard with buttons, an on-message flag, and notification preference. The message is then sent using the run() method. ```java import space.zoommax.view.TextMessage; public class example { public static void main(String[] args) { TextMessage textMessage = TextMessage.builder() .text("Hello") .chatId(123456789) .keyboard(Keyboard.builder() .chatId(123456789) .code("{Google;https://google.ru}{Yandex;https://ya.ru} {Start;strt}") .build()) .onMessageFlag("start") .notify(false) .build(); textMessage.run(); } } ``` -------------------------------- ### Create and Send Inline Keyboard (Java) Source: https://zoommax.github.io/OneMessageBot/viewmessage/inlinekeyboard Demonstrates how to use the InlineKeyboard builder to create an inline keyboard with specified buttons and send it to a chat. Requires the space.zoommax.view.InlineKeyboard class. It takes a chatId and a code string defining the buttons and their actions. ```java import space.zoommax.view.InlineKeyboard; public class example { public static void main(String[] args) { InlineKeyboard inlineKeyboard = InlineKeyboard.builder() .chatId(123456789) .code("{Google;https://google.ru}{Yandex;https://ya.ru}\n" + "{Start;strt}") .build(); inlineKeyboard.run(); } } ``` -------------------------------- ### Create Buttons using Button Object (Java) Source: https://zoommax.github.io/OneMessageBot/keyboard/button This method creates Telegram buttons by instantiating the Button class with 'text' and 'action' fields. The 'action' field determines the button's behavior: 'mapp' for Mini Apps, 'http' or 'tg' for links, and any other string for callback actions. ```java Button button1 = new Button("I will open a Telegram Mini App", "mapphttp://example.com"); Button button2 = new Button("I will open a link", "http://example.com"); Button button3 = new Button("I will also open a link", "tg://username"); Button button4 = new Button("I will perform a callback action", "any_data"); ``` -------------------------------- ### Create Telegram Keyboard with List of Buttons Source: https://zoommax.github.io/OneMessageBot/keyboard/keyboard Shows how to construct a Telegram keyboard programmatically using a list of `Button` objects organized into rows. This method uses the `keyboardButtons` parameter of the `Keyboard.builder`. Each inner list represents a row of buttons, and `Button` objects are defined with text and an optional URL or callback data. ```java import space.zoommax.utils.keyboard.Button; import space.zoommax.utils.keyboard.Keyboard; import java.util.List; import java.util.ArrayList; List