我有一个任务: 需要发送带有电报bot中本地文件夹的照片。
前提条件:
我使用了这个图书馆https://github.com/rubenlagus/TelegramBots
在Pom文件中:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.rubenlagus</groupId>
<artifactId>TelegramBots</artifactId>
<version>4.1</version>
</dependency>
如何创建发送方法?
我试图这样做:
public void sendInTelegram() {
try {
TelegramLongPollingBot telegramLongPollingBot = new TelegramLongPollingBot() {
@Override
public String getBotToken() {
return "My_Token";
}
@Override
public void onUpdateReceived(Update update) {
try {
SendPhoto message = new SendPhoto().setPhoto("SomeText", new FileInputStream(new File("/root/index.png")));
this.sendPhoto(message);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
@Override
public String getBotUsername() {
return "my_bot";
}
};
} catch (Exception e) {
logger.error("Send in Telegram fail");
Assert.fail("Send in Telegram fail");
}
但是his.sendPhoto(message); sendPhoto无法解析 enter image description here
请告诉我不足以发送照片吗?
答案 0 :(得分:0)
使用execute
,而不是sendPhoto
:
SendPhoto message = new SendPhoto().setPhoto("SomeText", new FileInputStream(new File("/root/index.png")));
this.execute(message);