Fix FAQ.md according to API changes
This commit is contained in:
parent
b2fcbaa3c2
commit
bd2aa24e00
@ -79,29 +79,29 @@ Quick example here that is showing ChactActions for commands like "/type" or "/r
|
|||||||
```java
|
```java
|
||||||
if (update.hasMessage() && update.getMessage().hasText()) {
|
if (update.hasMessage() && update.getMessage().hasText()) {
|
||||||
|
|
||||||
String text = update.getMessage().getText();
|
String text = update.getMessage().getText();
|
||||||
|
|
||||||
SendChatAction sendChatAction = new SendChatAction();
|
SendChatAction sendChatAction = new SendChatAction();
|
||||||
sendChatAction.setChatId(update.getMessage().getChatId());
|
sendChatAction.setChatId(update.getMessage().getChatId());
|
||||||
|
|
||||||
if (text.equals("/type")) {
|
if (text.equals("/type")) {
|
||||||
// -> "typing"
|
// -> "typing"
|
||||||
sendChatAction.setAction(ActionType.TYPING);
|
sendChatAction.setAction(ActionType.TYPING);
|
||||||
// -> "recording a voice message"
|
// -> "recording a voice message"
|
||||||
} else if (text.equals("/record_audio")) {
|
} else if (text.equals("/record_audio")) {
|
||||||
sendChatAction.setAction(ActionType.RECORDAUDIO);
|
sendChatAction.setAction(ActionType.RECORDAUDIO);
|
||||||
} else {
|
} else {
|
||||||
// -> more actions in the Enum ActionType
|
// -> more actions in the Enum ActionType
|
||||||
// For information: https://core.telegram.org/bots/api#sendchataction
|
// For information: https://core.telegram.org/bots/api#sendchataction
|
||||||
sendChatAction.setAction(ActionType.UPLOADDOCUMENT);
|
sendChatAction.setAction(ActionType.UPLOADDOCUMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Boolean wasSuccessfull = execute(sendChatAction);
|
Boolean wasSuccessfull = execute(sendChatAction);
|
||||||
} catch (TelegramApiException e) {
|
} catch (TelegramApiException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
|
|||||||
// Set destination chat id
|
// Set destination chat id
|
||||||
sendPhotoRequest.setChatId(chatId);
|
sendPhotoRequest.setChatId(chatId);
|
||||||
// Set the photo url as a simple photo
|
// Set the photo url as a simple photo
|
||||||
sendPhotoRequest.setPhoto(url);
|
sendPhotoRequest.setPhoto(new InputFile(url));
|
||||||
try {
|
try {
|
||||||
// Execute the method
|
// Execute the method
|
||||||
execute(sendPhotoRequest);
|
execute(sendPhotoRequest);
|
||||||
@ -131,7 +131,7 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
|
|||||||
// Set destination chat id
|
// Set destination chat id
|
||||||
sendPhotoRequest.setChatId(chatId);
|
sendPhotoRequest.setChatId(chatId);
|
||||||
// Set the photo url as a simple photo
|
// Set the photo url as a simple photo
|
||||||
sendPhotoRequest.setPhoto(fileId);
|
sendPhotoRequest.setPhoto(new InputFile(fileId));
|
||||||
try {
|
try {
|
||||||
// Execute the method
|
// Execute the method
|
||||||
execute(sendPhotoRequest);
|
execute(sendPhotoRequest);
|
||||||
@ -145,8 +145,8 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
|
|||||||
SendPhoto sendPhotoRequest = new SendPhoto();
|
SendPhoto sendPhotoRequest = new SendPhoto();
|
||||||
// Set destination chat id
|
// Set destination chat id
|
||||||
sendPhotoRequest.setChatId(chatId);
|
sendPhotoRequest.setChatId(chatId);
|
||||||
// Set the photo file as a new photo (You can also use InputStream with a method overload)
|
// Set the photo file as a new photo (You can also use InputStream with a constructor overload)
|
||||||
sendPhotoRequest.setNewPhoto(new File(filePath));
|
sendPhotoRequest.setPhoto(new InputFile(new File(filePath)));
|
||||||
try {
|
try {
|
||||||
// Execute the method
|
// Execute the method
|
||||||
execute(sendPhotoRequest);
|
execute(sendPhotoRequest);
|
||||||
@ -162,24 +162,23 @@ In this example we will check if user sends to bot a photo, if it is, get Photo'
|
|||||||
```java
|
```java
|
||||||
// If it is a photo
|
// If it is a photo
|
||||||
if (update.hasMessage() && update.getMessage().hasPhoto()) {
|
if (update.hasMessage() && update.getMessage().hasPhoto()) {
|
||||||
// Array with photos
|
// Array with photos
|
||||||
List<PhotoSize> photos = update.getMessage().getPhoto();
|
List<PhotoSize> photos = update.getMessage().getPhoto();
|
||||||
// Get largest photo's file_id
|
// Get largest photo's file_id
|
||||||
String f_id = photos.stream()
|
String f_id = photos.stream()
|
||||||
.sorted(Comparator.comparing(PhotoSize::getFileSize).reversed())
|
.max(Comparator.comparing(PhotoSize::getFileSize))
|
||||||
.findFirst()
|
.orElseThrow().getFileId();
|
||||||
.orElse(null).getFileId();
|
// Send photo by file_id we got before
|
||||||
// Send photo by file_id we got before
|
SendPhoto msg = new SendPhoto()
|
||||||
SendPhoto msg = new SendPhoto()
|
.setChatId(update.getMessage().getChatId())
|
||||||
.setChatId(update.getMessage().getChatId())
|
.setPhoto(new InputFile(f_id))
|
||||||
.setPhoto(f_id)
|
.setCaption("Photo");
|
||||||
.setCaption("Photo");
|
try {
|
||||||
try {
|
execute(msg); // Call method to send the photo
|
||||||
execute(msg); // Call method to send the photo
|
} catch (TelegramApiException e) {
|
||||||
} catch (TelegramApiException e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## <a id="how_to_use_custom_keyboards"></a>How to use custom keyboards? ##
|
## <a id="how_to_use_custom_keyboards"></a>How to use custom keyboards? ##
|
||||||
@ -264,9 +263,9 @@ Your main spring boot class should look like this:
|
|||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class YourApplicationMainClass {
|
public class YourApplicationMainClass {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(YourApplicationMainClass.class, args);
|
SpringApplication.run(YourApplicationMainClass.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user