本文整理汇总了Java中org.telegram.telegrambots.api.objects.Message.getChatId方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getChatId方法的具体用法?Java Message.getChatId怎么用?Java Message.getChatId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.telegram.telegrambots.api.objects.Message
的用法示例。
在下文中一共展示了Message.getChatId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasPhoto()) {
Message message = update.getMessage();
long chatId = message.getChatId();
// get the last photo - it seems to be the bigger one
List<PhotoSize> photos = message.getPhoto();
PhotoSize photo = photos.get(photos.size() - 1);
String id = photo.getFileId();
try {
GetFile getFile = new GetFile();
getFile.setFileId(id);
String filePath = getFile(getFile).getFileUrl(getBotToken());
// TODO: cache images?
logger.info("== DOWNLOADING IMAGE " + filePath);
URL url = new URL(filePath);
String caption = Classifier.classify(url.openStream());
logger.info("Caption for image " + filePath + ":\n" + caption);
sendPhotoMessage(chatId, id, caption);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例2: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
SendMessage response = new SendMessage();
Long chatId = message.getChatId();
response.setChatId(chatId);
String text = message.getText();
response.setText(text);
try {
sendMessage(response);
logger.info("Sent message \"{}\" to {}", text, chatId);
} catch (TelegramApiException e) {
logger.error("Failed to send message \"{}\" to {} due to error: {}", text, chatId, e.getMessage());
}
}
}
示例3: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
LOGGER.debug("Received: {}", update);
final Message message = Optional.ofNullable(update.getMessage()).orElse(update.getEditedMessage());
final Long chatId = message.getChatId();
if (!telegramProperties.getChatId().equals(chatId)) {
LOGGER.debug("Unauthorized access, ignoring (chat_id: {}, expected: {})", update.getMessage().getChatId(), telegramProperties.getChatId());
return;
}
final String command = message.getText();
context.publishEvent(new CommandEvent(command));
}
示例4: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if ("/subscribe".equalsIgnoreCase(message.getText().trim())) {
Long chatId = message.getChatId();
String url = baseurl + "/user/updateConfig?telegramChatId=" + chatId;
sendMessageToChat("Please open <a href=\"" + url + "\">Link</a> to register chat", chatId);
}
}
}