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


Java SendMessage类代码示例

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


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

示例1: onUpdateReceived

import org.telegram.telegrambots.api.methods.send.SendMessage; //导入依赖的package包/类
@Override
/*
 * 接收訊息時 運行此內容
 */
public void onUpdateReceived(Update update) {
  /*
   * 在命令欄顯示接收的消息 json格式
   */
  System.out.println(update.getMessage());
  try{
    /*
     * 設定發消息內容 封裝為一個新封包
     */
    SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
            .setChatId(update.getMessage().getChatId())
            .setReplyToMessageId(update.getMessage().getMessageId())
            .setText("Hellow World!");
    /*
     * 調用super class的sendMessage功能 把封包發出去
     */
    this.sendMessage(message);
  }catch(Exception ex){
    System.out.println("Error");
  }
}
 
开发者ID:slgphantom,项目名称:yearyearyear,代码行数:26,代码来源:TelegramBot.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();
        System.out.println(message);
        List<User> newUsers = update.getMessage().getNewChatMembers();
        if (newUsers != null) {
            String welcomeMessage = "Bienvenido al grupo Java Studio: ";

            for (User newUser : newUsers) {
                String user = newUser.getUserName().equals("null") ? newUser.getFirstName()
                        : "@" + newUser.getUserName();
                welcomeMessage += user + " ";
            }
            SendMessage welcomeSendMessage = new SendMessage()
                    .setChatId(message.getChatId())
                    .setText(welcomeMessage);
            try {
                sendMessage(welcomeSendMessage);
            } catch (TelegramApiException ex) {
                Logger.getLogger(CoffeeAndyBot.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }
}
 
开发者ID:Java-Studio-Telegram-Group,项目名称:Coffee_AndyBot,代码行数:27,代码来源:CoffeeAndyBot.java

示例4: sendReplyKeyboard

import org.telegram.telegrambots.api.methods.send.SendMessage; //导入依赖的package包/类
public Message sendReplyKeyboard(long chatId, String message, String[][] keyboardText, boolean oneTimeKeyboard) {
    ReplyKeyboardMarkup keyboard = new ReplyKeyboardMarkup();
    keyboard.setOneTimeKeyboard(oneTimeKeyboard);

    List<KeyboardRow> keyboardRows = new ArrayList<>();
    for (String[] rows : keyboardText) {
        KeyboardRow keyboardRow = new KeyboardRow();
        for (String row : rows) {
            keyboardRow.add(row);
        }
        keyboardRows.add(keyboardRow);
    }
    keyboard.setKeyboard(keyboardRows);

    SendMessage sendMessage = new SendMessage(chatId, message);
    sendMessage.setReplyMarkup(keyboard);

    return execute(sendMessage);
}
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:20,代码来源:TgMessageServiceContextless.java

示例5: onUpdateReceived

import org.telegram.telegrambots.api.methods.send.SendMessage; //导入依赖的package包/类
@Override
public void onUpdateReceived(Update arg0) {
	
	SendMessage msg=null;
	if(arg0.getMessage().isCommand())
		
		msg = createMessage(JlasniCommand(arg0.getMessage().getText()), arg0.getMessage().getChatId());
	else
		msg= createMessage("Error, no es un comando", arg0.getMessage().getChatId());
		
	try {
		execute(msg);
	}catch (TelegramApiException e) {
		// TODO: handle exception
		e.printStackTrace();
	}
	
	
}
 
开发者ID:zerasul,项目名称:lasnibot,代码行数:20,代码来源:JlasniBot.java

示例6: 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

示例7: 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

示例8: 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

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

示例10: execute

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

    String userName = user.getFirstName() + " " + user.getLastName();

    if (databseManager.getUserStateForCommandsBot(user.getId())) {
        messageBuilder.append("Hi ").append(userName).append("\n");
        messageBuilder.append("i think we know each other already!");
    } else {
        databseManager.setUserStateForCommandsBot(user.getId(), true);
        messageBuilder.append("Welcome ").append(userName).append("\n");
        messageBuilder.append("this bot will demonstrate you the command feature of the Java TelegramBots API!");
    }

    SendMessage answer = new SendMessage();
    answer.setChatId(chat.getId().toString());
    answer.setText(messageBuilder.toString());

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

示例11: 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

示例12: execute

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

    if (!DatabaseManager.getInstance().getUserStateForCommandsBot(user.getId())) {
        return;
    }

    StringBuilder helpMessageBuilder = new StringBuilder("<b>Help</b>\n");
    helpMessageBuilder.append("These are the registered commands for this Bot:\n\n");

    for (BotCommand botCommand : commandRegistry.getRegisteredCommands()) {
        helpMessageBuilder.append(botCommand.toString()).append("\n\n");
    }

    SendMessage helpMessage = new SendMessage();
    helpMessage.setChatId(chat.getId().toString());
    helpMessage.enableHtml(true);
    helpMessage.setText(helpMessageBuilder.toString());

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

示例13: CommandsHandler

import org.telegram.telegrambots.api.methods.send.SendMessage; //导入依赖的package包/类
/**
 * Constructor.
 */
public CommandsHandler() {
    register(new HelloCommand());
    register(new StartCommand());
    register(new StopCommand());
    HelpCommand helpCommand = new HelpCommand(this);
    register(helpCommand);

    registerDefaultAction((absSender, message) -> {
        SendMessage commandUnknownMessage = new SendMessage();
        commandUnknownMessage.setChatId(message.getChatId());
        commandUnknownMessage.setText("The command '" + message.getText() + "' is not known by this bot. Here comes some help " + Emoji.AMBULANCE);
        try {
            absSender.sendMessage(commandUnknownMessage);
        } catch (TelegramApiException e) {
            BotLogger.error(LOGTAG, e);
        }
        helpCommand.execute(absSender, message.getFrom(), message.getChat(), new String[] {});
    });
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:23,代码来源:CommandsHandler.java

示例14: 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

示例15: sendHelpMessage

import org.telegram.telegrambots.api.methods.send.SendMessage; //导入依赖的package包/类
private void sendHelpMessage(Long chatId, Integer messageId, ReplyKeyboardMarkup replyKeyboardMarkup) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(chatId);
    sendMessage.setReplyToMessageId(messageId);
    if (replyKeyboardMarkup != null) {
        sendMessage.setReplyMarkup(replyKeyboardMarkup);
    }

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


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