maratik123 / spring-telegram-example

example telegram bot
Apache License 2.0
0 stars 0 forks source link

Unsupported Hanlder with SendDocument Method #4

Closed BlackRose01 closed 5 years ago

BlackRose01 commented 5 years ago

Hello there,

I want to send documents but i always get the following error.

Unsupported handler 'TelegramHandler{bean=de.pagedesk.controller.TelegramController@642f8b7f, method=public org.telegram.telegrambots.meta.api.methods.send.SendDocument de.pagedesk.controller.TelegramController.getDocument(org.telegram.telegrambots.meta.api.objects.User) throws java.io.FileNotFoundException, telegramCommand=@name.maratik.spring.telegram.annotation.TelegramCommand(value=[/sola], hidden=false, description=Testmethode, commands=[/sola], isHelp=false)}'

`@TelegramCommand(value = "/sola", description = "Testmethode") public SendDocument getDocument(User user) throws FileNotFoundException { System.out.println("moni"); FileInputStream fis = new FileInputStream(new File("")); SendDocument sendDocumentRequest = new SendDocument();

sendDocumentRequest.setChatId(user.getId().longValue());
sendDocumentRequest.setDocument("Testdokument", fis);
sendDocumentRequest.setCaption("Test");
//sendDocument(sendDocumentRequest);

return sendDocumentRequest;
//return new SendDocument().setChatId(user.getId().toString()).setDocument("Testdokument", fis).setCaption("Test");
//return new SendDocument().setChatId(user.getId().longValue()).setNewDocument(new File("<DocumentPath>").getAbsoluteFile());

}`

Regardings, BlackRose01

maratik123 commented 5 years ago

Hello, SendDocument extends PartialBotApiMethod (and not BotApiMethod), so it can not be used as response on processing webhook (and the same restriction is applied in long polling mode for consistency).

So you can use SendDocument command as follow:

@TelegramCommand(value = "/sola", description = "Testmethode")
public void getDocument(User user, DefaultAbsSender absSender) throws FileNotFoundException {
  System.out.println("moni");
  FileInputStream fis = new FileInputStream(new File(""));
  SendDocument sendDocumentRequest = new SendDocument();
  sendDocumentRequest.setChatId(user.getId().longValue());
  sendDocumentRequest.setDocument("Testdokument", fis);
  sendDocumentRequest.setCaption("Test");
  absSender.execute(sendDocumentRequest);
}