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


Java TelegramApiException类代码示例

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


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

示例1: main

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
public static void main(String args[]){
  /*
   * 創建一個新的telegramAPI 在內存裡面
   */
  TelegramBotsApi tgBot = new TelegramBotsApi();    
  /*
   * 初始化telegramAPI的所有函數
   */
  ApiContextInitializer.init();
  /*
   *try{}catch(Exception e) 是一組條件 代表嘗試 如果有程序錯誤 執行catch 如沒有 catch則不會執行
   */
      try {
        /*
         * 把創建出來的telegramAPI與機器人連接
         */
        tgBot.registerBot(new TelegramBot());
      } catch (TelegramApiException e) {
        System.out.println("error");
      }
}
 
开发者ID:slgphantom,项目名称:yearyearyear,代码行数:22,代码来源:Example.java

示例2: executeSell

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
/**
 * Executes a sell for the given trade and current rate
 *
 * @param trade Trade instance
 * @param currentRate current rate
 *
 * @throws IOException if any I/O error occurs while contacting the exchange
 * @throws TelegramApiException if any error occur while using the Telegram API
 */
private void executeSell(TradeEntity trade, BigDecimal currentRate) throws IOException, TelegramApiException {
    // Get available balance
    String currency = trade.getPair().split("/")[1];
    BigDecimal balance = exchangeService.getBalance(Currency.getInstance(currency));
    List<CurrencyPair> whitelist = properties.getPairWhitelist();

    BigDecimal profit = tradeService.executeSellOrder(trade, currentRate, balance);
    whitelist.add(new CurrencyPair(trade.getPair()));
    String message = String.format("*%s:* Selling [%s](%s) at rate `%s (profit: %s%%)`",
            trade.getExchange(),
            trade.getPair(),
            exchangeService.getPairDetailUrl(trade.getPair()),
            trade.getCloseRate(),
            profit.round(new MathContext(2)));
    LOGGER.info(message);
    telegramService.sendMessage(message);
}
 
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:27,代码来源:FreqTradeMainRunner.java

示例3: onCommandEvent

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
@EventListener
public void onCommandEvent(CommandEvent event) {
    LOGGER.debug("Received event: {}", event);

    final String command = event.getCommand();
    if (!availableCommandNames.contains(command)) {

        final String unknownCommandMessage = String.format("Unkown command received: %s", command);
        LOGGER.debug(unknownCommandMessage);

        try {
            telegramService.sendMessage(unknownCommandMessage);
            telegramService.sendMessage(String.format("Available commands: %s", availableCommandNames));
        } catch (TelegramApiException e) {
            LOGGER.warn("Unable to reply to message", e);
        }
    }

}
 
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:20,代码来源:CommandEventListener.java

示例4: main

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
public static void main(String[] args) {

    	System.out.println("started");
    	
        // Initialize Api Context
        ApiContextInitializer.init();

        // Instantiate Telegram Bots API
        TelegramBotsApi botsApi = new TelegramBotsApi();

        // Register our bot
        try {
            botsApi.registerBot(new SchoolAssistantBot());
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
        
	}
 
开发者ID:calmyourtities,项目名称:school-assistant,代码行数:19,代码来源:Main.java

示例5: onUpdateReceived

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的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

示例6: main

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
/**
 * Fa partire il client.<BR>
 * Uso: <code>java TestClient nick debugLevel</code><br>
 */
public static void main(String[] args) {
	boolean ldeb;
	if (args.length < 2)
		misuse();
	String nick = args[0];
	int aDeb = Integer.parseInt(args[1]);
	if (aDeb == 1)
		ldeb = true;
	else
		ldeb = false;

	// Initialize Api Context
	ApiContextInitializer.init();

	// Instantiate Telegram Bots API
	TelegramBotsApi botsApi = new TelegramBotsApi();

	// Register our bot
	try {
		botsApi.registerBot(new TelegramIlnBot(nick, ldeb, new LogServer("iln")));
	} catch (TelegramApiException e) {
		e.printStackTrace();
	}
}
 
开发者ID:alex321v,项目名称:iln,代码行数:29,代码来源:TelegramClient.java

示例7: downloadFromFileId

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
/**
 * @return a list of {@literal Triplet<byte[] data, String filename, String fileExtension>}
 */
private Triplet<byte[], String, String> downloadFromFileId(String fileId) throws TelegramApiException, IOException {
    GetFile getFile = new GetFile();
    getFile.setFileId(fileId);

    File file = execute(getFile);
    URL fileUrl = new URL(file.getFileUrl(configs.get(TOKEN_KEY)));
    HttpURLConnection httpConn = (HttpURLConnection) fileUrl.openConnection();
    InputStream inputStream = httpConn.getInputStream();
    byte[] output = IOUtils.toByteArray(inputStream);

    String fileName = file.getFilePath();
    String[] fileNameSplitted = fileName.split("\\.");
    String extension = fileNameSplitted[fileNameSplitted.length - 1];
    String filenameWithoutExtension = fileName.substring(0, fileName.length() - extension.length() - 1);

    inputStream.close();
    httpConn.disconnect();

    return new Triplet<>(output, filenameWithoutExtension, extension);
}
 
开发者ID:KDE,项目名称:brooklyn,代码行数:24,代码来源:TelegramBot.java

示例8: onAttachmentReceived

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
private void onAttachmentReceived(BotMessage botMsg, Message message,
                                  String fileId, BotDocumentType type,
                                  String msgId) {
    try {
        Triplet<byte[], String, String> data = downloadFromFileId(fileId);

        BotTextMessage textMessage = new BotTextMessage(botMsg, message.getCaption());
        BotDocumentMessage documentMessage = new BotDocumentMessage(textMessage,
                data.getValue1(), data.getValue2(), data.getValue0(), type);

        botsController.sendMessage(documentMessage,
                Long.toString(message.getChatId()), Optional.of(msgId));
    } catch (TelegramApiException | IOException e) {
        logger.error("Error loading the media received. ", e);
    }
}
 
开发者ID:KDE,项目名称:brooklyn,代码行数:17,代码来源:TelegramBot.java

示例9: sendMessage

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
@Override
public Optional<String> sendMessage(BotTextMessage msg, String channelTo) {
    SendMessage message = new SendMessage()
            .setChatId(channelTo)
            .setText(BotsController.messageFormatter(
                    msg.getBotFrom(), msg.getChannelFrom(),
                    msg.getNicknameFrom(), Optional.ofNullable(msg.getText())));
    try {
        Message sentMessage = execute(message);
        return Optional.of(sentMessage.getMessageId().toString());
    } catch (TelegramApiException e) {
        logger.error("Failed to send message from {} to TelegramBot",
                msg.getBotFrom().getId(), e);
        return Optional.empty();
    }
}
 
开发者ID:KDE,项目名称:brooklyn,代码行数:17,代码来源:TelegramBot.java

示例10: onUpdateReceived

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的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

示例11: onUpdateReceived

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的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

示例12: main

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
public static void main(String[] args) {
	ApiContextInitializer.init();
	TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
	try {
		EntenBot entenBot = new EntenBot();
		telegramBotsApi.registerBot(entenBot);
	} catch (TelegramApiException e){
		BotLogger.error("LOGTAG", e);
	}
}
 
开发者ID:Bergiu,项目名称:TelegramEntenBot,代码行数:11,代码来源:Main.java

示例13: onUpdateReceived

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的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

示例14: sendMessage

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
private void sendMessage(long chat_id, String text) {
    SendMessage message = new SendMessage();
    message.setChatId(chat_id);
    message.setText(text);
    try{
        sendMessage(message);
    } catch (TelegramApiException e) {
        e.printStackTrace();
    }
}
 
开发者ID:franziheck,项目名称:Paulette,代码行数:11,代码来源:Paulette.java

示例15: registerBots

import org.telegram.telegrambots.exceptions.TelegramApiException; //导入依赖的package包/类
private static void registerBots(){
    TelegramBotsApi botsApi = new TelegramBotsApi();

    try{
        botsApi.registerBot(new Paulette());
        System.out.println("Success! BotServer connected to Telegram Server");
    } catch (TelegramApiException e) {
        System.out.println("Unable to connect to Telegram Server. Please check BotToken and Internet Settings");
    }
}
 
开发者ID:franziheck,项目名称:Paulette,代码行数:11,代码来源:Main.java


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