当前位置: 首页>>代码示例>>Java>>正文


Java SendMessage.setChatId方法代码示例

本文整理汇总了Java中org.telegram.telegrambots.api.methods.send.SendMessage.setChatId方法的典型用法代码示例。如果您正苦于以下问题:Java SendMessage.setChatId方法的具体用法?Java SendMessage.setChatId怎么用?Java SendMessage.setChatId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.telegram.telegrambots.api.methods.send.SendMessage的用法示例。


在下文中一共展示了SendMessage.setChatId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] arguments) {
    DatabaseManager dbManager = DatabaseManager.getInstance();

    if (dbManager.getUserStateForCommandsBot(user.getId())) {
        dbManager.setUserStateForCommandsBot(user.getId(), false);
        String userName = user.getFirstName() + " " + user.getLastName();

        SendMessage answer = new SendMessage();
        answer.setChatId(chat.getId().toString());
        answer.setText("Good bye " + userName + "\n" + "Hope to see you soon!");

        try {
            absSender.sendMessage(answer);
        } catch (TelegramApiException e) {
            BotLogger.error(LOGTAG, e);
        }
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:20,代码来源:StopCommand.java

示例2: 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();
		}
		
	}
 
开发者ID:InsightLab,项目名称:telegram-bots,代码行数:22,代码来源:StartCommand.java

示例3: 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()
}
 
开发者ID:gomgomdev,项目名称:telegram-bot_misebot,代码行数:27,代码来源:TellMiseHandlers.java

示例4: 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()
                                         ));
    }
}
 
开发者ID:dmitriid,项目名称:tetrad,代码行数:18,代码来源:TetradTelegram.java

示例5: 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());
		}
	}
}
 
开发者ID:xabgesagtx,项目名称:telegram-spring-boot-starter-example,代码行数:18,代码来源:ExampleBot.java

示例6: onSetLanguageCommand

import org.telegram.telegrambots.api.methods.send.SendMessage; //导入方法依赖的package包/类
private void onSetLanguageCommand(Message message, String language) throws InvalidObjectException, TelegramApiException {
    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() + " " + Emoji.LEFT_RIGHT_ARROW.toString() + " " + 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));
    sendMessage(sendMessageRequest);
    languageMessages.add(message.getFrom().getId());
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:21,代码来源:FilesHandlers.java

示例7: 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());
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:18,代码来源:FilesHandlers.java

示例8: 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);
            }
        }
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:24,代码来源:CommandsHandler.java

示例9: 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);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:20,代码来源:WeatherHandlers.java

示例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);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:25,代码来源:DirectionsHandlers.java

示例11: 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;
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:18,代码来源:WeatherHandlers.java

示例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();
    }
}
 
开发者ID:freedomotic,项目名称:freedomotic,代码行数:33,代码来源:FreedomoticBotHandlers.java

示例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);
        }
    }

}
 
开发者ID:freedomotic,项目名称:freedomotic,代码行数:22,代码来源:FreedomoticBotHandlers.java

示例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();
			}
		}
		
	}
	
}
 
开发者ID:InsightLab,项目名称:telegram-bots,代码行数:29,代码来源:QualisBot.java

示例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();
		}
	}
}
 
开发者ID:Bergiu,项目名称:TelegramEntenBot,代码行数:35,代码来源:EntenBot.java


注:本文中的org.telegram.telegrambots.api.methods.send.SendMessage.setChatId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。