本文整理汇总了Java中org.telegram.telegrambots.api.methods.send.SendMessage.setText方法的典型用法代码示例。如果您正苦于以下问题:Java SendMessage.setText方法的具体用法?Java SendMessage.setText怎么用?Java SendMessage.setText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.telegram.telegrambots.api.methods.send.SendMessage
的用法示例。
在下文中一共展示了SendMessage.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
public void run(Update update, TelegramLongPollingBot bot) {
SendMessage sm = new SendMessage();
sm.setChatId(update.getMessage().getChatId());
sm.setParseMode(ParseMode.HTML);
String finalMessage = new String("<b>Verificador de Qualis - CAPES</b>\n");
finalMessage = finalMessage.concat("\nUtilize os seguintes comandos para consulta\n");
finalMessage = finalMessage.concat("\n<b>/conferencia</b> <i>sigla_conferencia</i> OU <i>nome_conferencia</i>");
finalMessage = finalMessage.concat("\n<b>/periodico</b> <i>issn_periodico</i> OU <i>nome_periodico</i>");
sm.setText(finalMessage);
try {
bot.sendMessage(sm);
} catch (TelegramApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例2: onUpdateReceived
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
// 업데이트가 메시지를 가지고 있는지 확인합니다.
if(update.hasMessage()){
Message message = update.getMessage();
String answerMessage = message.getText().toString(); // 메시지를 String 형태로 받아옵니다.
char answerLocation[] = new char[10];
if(answerMessage.startsWith("/ㅁㅅ ")) {
answerMessage.getChars(4, answerMessage.length(), answerLocation, 0);
// 지역명이 전달되었다면 char 배열로 받아옵니다. (최대 10자로 제한두고자 함)
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(message.getChatId().toString()); //who should get the message? the sender from which we got the message...
String str = new String(answerLocation, 0, answerMessage.length()-4); // 지역명을 String으로 재반환합니다.
sendMessageRequest.setText(AnswerReport.getPMStatus(str)); // 지역명을 AnswerReport 클래스로 넘겨줍니다.
try {
sendMessage(sendMessageRequest); //at the end, so some magic and send the message ;)
} catch (TelegramApiException e) {
e.printStackTrace();
}//end catch()
}//end if()
}//end if()
}
示例3: post
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
public void post(FirehoseMessage firehoseMessage) {
logger.info("Publish message " + firehoseMessage.toLogString());
SendMessage sendMessageReq = new SendMessage();
sendMessageReq.setChatId(firehoseMessage.service);
sendMessageReq.enableMarkdown(true);
sendMessageReq.setText("*" + firehoseMessage.user + "*: " + firehoseMessage.content);
try {
execute(sendMessageReq);
} catch (TelegramApiException e) {
logger.error(MessageFormat.format("Error publishing message. Message: {0} Original message: {1}",
e.getMessage(),
firehoseMessage.toLogString()
));
}
}
示例4: onUpdateReceived
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的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());
}
}
}
示例5: showMainMenu
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
public void showMainMenu(final Message request, final TGSession session) throws TelegramApiException {
final ReplyKeyboardMarkup replyKeyboardMarkup = getMainMenuKeyboard();
final SendMessage msg =
createMessageWithKeyboard(request.getChatId().toString(), request.getMessageId(), replyKeyboardMarkup);
if (session.isNew()) {
session.setNew(false);
msg.setText("Привет, либо ты тут в первый раз, "
+ "либо мы _берега попутали_.\n"
+ "Пиши -- от души.");
} else {
msg.setText("Пиши -- от души.");
}
sendMessage(msg);
}
示例6: onLanguageReceived
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
private void onLanguageReceived(Message message) throws InvalidObjectException, TelegramApiException {
String[] parts = message.getText().split(Emoji.LEFT_RIGHT_ARROW.toString(), 2);
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(message.getChatId());
if (LocalisationService.getLanguageByCode(parts[0].trim()) != null) {
DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim());
sendMessageRequest.setText(LocalisationService.getString("languageModified", parts[0].trim()));
} else {
sendMessageRequest.setText(LocalisationService.getString("errorLanguage"));
}
sendMessageRequest.setReplyToMessageId(message.getMessageId());
ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
replyKeyboardRemove.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
sendMessage(sendMessageRequest);
languageMessages.remove(message.getFrom().getId());
}
示例7: processNonCommandUpdate
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
@Override
public void processNonCommandUpdate(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (!DatabaseManager.getInstance().getUserStateForCommandsBot(message.getFrom().getId())) {
return;
}
if (message.hasText()) {
SendMessage echoMessage = new SendMessage();
echoMessage.setChatId(message.getChatId());
echoMessage.setText("Hey heres your message:\n" + message.getText());
try {
sendMessage(echoMessage);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
}
}
示例8: onCurrentChoosen
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
private static SendMessage onCurrentChoosen(Message message, String language) {
SendMessage sendMessage = new SendMessage();
sendMessage.enableMarkdown(true);
ReplyKeyboardMarkup replyKeyboardMarkup = getRecentsKeyboard(message.getFrom().getId(), language);
sendMessage.setReplyMarkup(replyKeyboardMarkup);
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setChatId(message.getChatId());
if (replyKeyboardMarkup.getKeyboard().size() > 3) {
sendMessage.setText(LocalisationService.getString("onCurrentCommandFromHistory", language));
} else {
sendMessage.setText(LocalisationService.getString("onCurrentCommandWithoutHistory", language));
}
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), CURRENTWEATHER);
return sendMessage;
}
示例9: processNonCommandUpdate
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
@Override
public void processNonCommandUpdate(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (message.hasText()) {
SendMessage echoMessage = new SendMessage();
echoMessage.setChatId(message.getChatId());
echoMessage.setText("Hey heres your message:\n" + message.getText());
try {
sendMessage(echoMessage);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
}
}
示例10: onSetLanguageCommand
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
private void onSetLanguageCommand(Message message, String language) throws InvalidObjectException {
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(message.getChatId());
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
List<LocalisationService.Language> languages = LocalisationService.getSupportedLanguages();
List<KeyboardRow> commands = new ArrayList<>();
for (LocalisationService.Language languageItem : languages) {
KeyboardRow commandRow = new KeyboardRow();
commandRow.add(languageItem.getCode() + " --> " + languageItem.getName());
commands.add(commandRow);
}
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboard(true);
replyKeyboardMarkup.setKeyboard(commands);
replyKeyboardMarkup.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language));
try {
sendMessage(sendMessageRequest);
languageMessages.add(message.getFrom().getId());
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
示例11: onNewAlertCityReceived
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
private static SendMessage onNewAlertCityReceived(Message message, String language) {
int userId = message.getFrom().getId();
Integer cityId = DatabaseManager.getInstance().getRecentWeatherIdByCity(userId, message.getText());
if (cityId != null) {
DatabaseManager.getInstance().createNewWeatherAlert(userId, cityId, message.getText());
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.enableMarkdown(true);
sendMessageRequest.setReplyMarkup(getAlertsKeyboard(language));
sendMessageRequest.setReplyToMessageId(message.getMessageId());
sendMessageRequest.setText(getChooseNewAlertSetMessage(message.getText(), language));
sendMessageRequest.setChatId(message.getChatId());
DatabaseManager.getInstance().insertWeatherState(userId, message.getChatId(), ALERT);
return sendMessageRequest;
} else {
return sendChooseOptionMessage(message.getChatId(), message.getMessageId(),
getRecentsKeyboard(message.getFrom().getId(), language, false), language);
}
}
示例12: mainMenu
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
/**
* Shows the main menu.
*
* @param message
*/
private void mainMenu(String message) {
SendMessage sendMessagerequest = new SendMessage();
sendMessagerequest.setChatId(message);
sendMessagerequest.setText(i18n.msg("welcome_message"));
// main keyboard
KeyboardRow row = new KeyboardRow();
row.add(new KeyboardButton(i18n.msg("rooms")));
row.add(new KeyboardButton(i18n.msg("objects")));
KeyboardRow row2 = new KeyboardRow();
row2.add(new KeyboardButton(i18n.msg("plugins")));
//row2.add(new KeyboardButton(i18n.msg("languages")));
ReplyKeyboardMarkup markup = new ReplyKeyboardMarkup();
markup.setResizeKeyboard(true);
ArrayList<KeyboardRow> rows = new ArrayList<>();
rows.add(row);
rows.add(row2);
markup.setKeyboard(rows);
sendMessagerequest.setReplyMarkup(markup);
try {
sendMessage(sendMessagerequest);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
示例13: sendMessageToChannel
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
/**
* Sends a message to the channel.
*
* @param chatID chat identifier
* @param text message to send
*/
public void sendMessageToChannel(String chatID, String text) {
//create an object that contains the information to send
SendMessage message = new SendMessage();
message.setChatId(chatID);
message.setText(text);
if (getChatID().equalsIgnoreCase(chatID)) {
try {
sendMessage(message);
} catch (TelegramApiException ex) {
LOG.error("Error sending the message ", ex);
}
}
}
示例14: onUpdateReceived
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
public void onUpdateReceived(Update update) {
if(update.hasMessage()) {
Message message = update.getMessage();
String[] command = message.getText().split(" ");
if(command[0].startsWith("/") && commandHash.containsKey(command[0])) {
commandHash.get(command[0]).run(update, this);
logger.write(update);
}
else {
SendMessage sm = new SendMessage();
sm.setChatId(update.getMessage().getChatId());
sm.setParseMode(ParseMode.HTML);
sm.setText("Comando Inválido. Digite <b>/ajuda</b> para a lista de comandos.");
try {
sendMessage(sm);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
示例15: onUpdateReceived
import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
// TODO Auto-generated method stub
System.out.println("Received msg");
if (update.hasMessage() && update.getMessage().hasText()) {
String text = update.getMessage().getText().toLowerCase();
SendMessage message = new SendMessage();
message.setChatId(update.getMessage().getChatId());
//write everything in lowercase in the contains
if(text.equals("/license") || text.equals("/license"+this.getBotUsername())){
message.setText("Welcome!\nThis bot is a program which is available under the MIT license at https://github.com/Bergiu/TelegramEntenBot");
}
else if(text.contains("ente")){
message.setText("*QUACK!*");
// } else if (text.contains("bla")){
// message.setText("*BLUB!*");
// } else if (text.contains("kuh")){
// message.setText("*MUUHH!*");
}
else if(text.contains("foss")){
message.setText("*FOOOOOOOSSSS <3!*");
}else if (text.contains("git") || text.contains("love")){
message.setText("*<3*");
} else {
return;
}
message.setParseMode("markdown");
try {
sendMessage(message); // Call method to send the message
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}