本文整理汇总了Java中org.telegram.telegrambots.api.objects.Message.getText方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getText方法的具体用法?Java Message.getText怎么用?Java Message.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.telegram.telegrambots.api.objects.Message
的用法示例。
在下文中一共展示了Message.getText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeCommand
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
/**
* Executes a command action if the command is registered.
*
* @note If the command is not registered and there is a default consumer,
* that action will be performed
*
* @param absSender absSender
* @param message input message
* @return True if a command or default action is executed, false otherwise
*/
public final boolean executeCommand(AbsSender absSender, Message message) {
if (message.hasText()) {
String text = message.getText();
if (text.startsWith(BotCommand.COMMAND_INIT_CHARACTER)) {
String commandMessage = text.substring(1);
String[] commandSplit = commandMessage.split(BotCommand.COMMAND_PARAMETER_SEPARATOR);
String command = removeUsernameFromCommandIfNeeded(commandSplit[0]);
if (commandRegistryMap.containsKey(command)) {
String[] parameters = Arrays.copyOfRange(commandSplit, 1, commandSplit.length);
commandRegistryMap.get(command).execute(absSender, message.getFrom(), message.getChat(), parameters);
return true;
} else if (defaultConsumer != null) {
defaultConsumer.accept(absSender, message);
return true;
}
}
}
return false;
}
示例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: executeCommand
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
/**
* Executes a command action if the command is registered.
*
* @note If the command is not registered and there is a default consumer,
* that action will be performed
*
* @param absSender absSender
* @param message input message
* @return True if a command or default action is executed, false otherwise
*/
public final boolean executeCommand(AbsSender absSender, Message message) {
if (message.hasText()) {
String text = message.getText();
if (text.startsWith(BotCommand.COMMAND_INIT_CHARACTER)) {
String commandMessage = text.substring(1);
String[] commandSplit = commandMessage.split(BotCommand.COMMAND_PARAMETER_SEPARATOR_REGEXP);
String command = removeUsernameFromCommandIfNeeded(commandSplit[0]);
if (commandRegistryMap.containsKey(command)) {
String[] parameters = Arrays.copyOfRange(commandSplit, 1, commandSplit.length);
commandRegistryMap.get(command).processMessage(absSender, message, parameters);
return true;
} else if (defaultConsumer != null) {
defaultConsumer.accept(absSender, message);
return true;
}
}
}
return false;
}
示例4: 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));
}
示例5: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
logger.info("Received update: " + update.toString());
logger.info("Has message: " + update.hasMessage());
if (!update.hasMessage()) {
return;
}
Message message = update.getMessage();
String username = Optional.ofNullable(message.getFrom().getUserName())
.orElse(
MessageFormat.format(
"{0} {1}",
message.getFrom().getFirstName(),
message.getFrom().getLastName())
);
FirehoseMessage firehoseMessage = new FirehoseMessage("telegram",
"post",
username,
message.getChat().getId().toString(),
message.getChat().getTitle(),
message.getText());
logger.info("Got event from service: " + firehoseMessage.toLogString());
logger.info("Timestamp: " + message.getDate() + " vs local " + startTimestamp);
if (message.getDate() < startTimestamp) {
return;
}
if (!message.hasText()) {
return;
}
callback.execute(firehoseMessage);
}
示例6: handleMessage
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void handleMessage(final Message request, final TGSession session) throws TelegramApiException {
final String text = request.getText();
if (getEntry().equals(text)) {
sendMessage(request.getChatId().toString(), Constants.BOT_SELF_DESCRIPTION);
return;
}
}
示例7: handleMessage
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void handleMessage(final Message request, final TGSession session) throws TelegramApiException {
final String text = request.getText();
if (getEntry().equals(text)) {
onMain(request, session);
return;
}
if (text.equals(BACK)) {
back(request, session);
return;
}
sendAction(request.getChatId().toString(), ActionType.TYPING);
final Rhyme rhyme = CleverEngine.getRhyme(text);
LOGGER.info("RHYME_REPORT\t"
+ session.getChatId() + "\t"
+ session.getUser().getId() + "\t"
+ session.getUser().getUserName() + "\t"
+ session.getUser().getFirstName() + "\t"
+ session.getUser().getLastName() + "\t"
+ text.replaceAll("\t", " ") + "\t"
+ (rhyme == null ? "NO_RHYME" : rhyme.getRhyme()) + "\t"
+ (rhyme == null ? "NO_SONG" : rhyme.getGopSong().getName()) + "\t"
+ (rhyme == null ? "NO_SONG" : rhyme.getGopSong().getAuthor()));
LOGGER.info("REPORT_CHAT_ID " + FileUtils.REPORT_CHAT_ID);
// sendMessage(
//// FileUtils.REPORT_CHAT_ID,
// request.getChatId().toString(),
// session.getUser().getUserName() + "\n"
// + session.getUser().getFirstName() + "\n"
// + session.getUser().getLastName() + "\n"
// + text.replaceAll("\t", " ") + "\n"
// + (rhyme == null ? "NO_RHYME" : rhyme.getRhyme()) + "\t");
if (rhyme != null) {
onRhymeFound(request, session, rhyme);
} else {
sendMessage(request.getChatId().toString(), "Ничего не нашли");
}
}