From 87fdde7fe15f73b7dccca4e81ae138659d5c943b Mon Sep 17 00:00:00 2001 From: Clevero Date: Wed, 17 Oct 2018 09:54:24 +0200 Subject: [PATCH] Update FAQ.md --- TelegramBots.wiki/FAQ.md | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/TelegramBots.wiki/FAQ.md b/TelegramBots.wiki/FAQ.md index eeac8dc7..c0e8727f 100644 --- a/TelegramBots.wiki/FAQ.md +++ b/TelegramBots.wiki/FAQ.md @@ -1,4 +1,5 @@ -* [How to get picture?](#how_to_get_picture) +* [How to get picture?](#how_to_get_picture) +* [How to display ChatActions like "typing" or "recording a voice message"?](#how_to_sendchataction) * [How to send photos?](#how_to_send_photos) * [How do I send photos by file_id?](#how_to_send_photos_file_id) * [How to use custom keyboards?](#how_to_use_custom_keyboards) @@ -74,6 +75,38 @@ public java.io.File downloadPhotoByFilePath(String filePath) { The returned `java.io.File` object will be your photo +## How to display ChatActions like "typing" or "recording a voice message"? ## +Quick example here that is showing ChactActions for commands like "/type" or "/record_audio" + +```java +if (update.hasMessage() && update.getMessage().hasText()) { + + String text = update.getMessage().getText(); + + SendChatAction sendChatAction = new SendChatAction(); + sendChatAction.setChatId(update.getMessage().getChatId()); + + if (text.equals("/type")) { + // -> "typing" + sendChatAction.setAction(ActionType.TYPING); + // -> "recording a voice message" + } else if (text.equals("/record_audio")) { + sendChatAction.setAction(ActionType.RECORDAUDIO); + } else { + // -> more actions in the Enum ActionType + // For information: https://core.telegram.org/bots/api#sendchataction + sendChatAction.setAction(ActionType.UPLOADDOCUMENT); + } + + try { + Boolean wasSuccessfull = execute(sendChatAction); + } catch (TelegramApiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +} +``` + ## How to send photos? ## There are several method to send a photo to an user using `sendPhoto` method: With a `file_id`, with an `url` or uploading the file. In this example, we assume that we already have the *chat_id* where we want to send the photo: @@ -252,4 +285,4 @@ After that your bot will look like: //Bot body. } ``` -Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api. \ No newline at end of file +Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api.