Merge pull request #530 from Clevero/master
add example for ChatActions to FAQ
This commit is contained in:
commit
698a9eec76
@ -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 to send photos?](#how_to_send_photos)
|
||||||
* [How do I send photos by file_id?](#how_to_send_photos_file_id)
|
* [How do I send photos by file_id?](#how_to_send_photos_file_id)
|
||||||
* [How to use custom keyboards?](#how_to_use_custom_keyboards)
|
* [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
|
The returned `java.io.File` object will be your photo
|
||||||
|
|
||||||
|
## <a id="how_to_sendchataction"></a>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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## <a id="how_to_send_photos"></a>How to send photos? ##
|
## <a id="how_to_send_photos"></a>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:
|
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.
|
//Bot body.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api.
|
Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api.
|
||||||
|
Loading…
Reference in New Issue
Block a user