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


Java TelegramBotAdapter类代码示例

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


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

示例1: executarBot

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
/**
 * Executa a inicializa��o do bot e realiza o 'polling' de mensagens enviadas
 */
public void executarBot() {
	TelegramBot bot = TelegramBotAdapter.build(TOKEN_ACESSO);
	int m = 0;

	while (true) {
		List<Update> updates = bot.execute(new GetUpdates().limit(100).offset(m)).updates();

		for (Update update : updates) {
			m = update.updateId() + 1;
			String mensagemRetorno = "";
			if (update.message() != null) {
				bot.execute(new SendChatAction(update.message().chat().id(), ChatAction.typing.name()));
				try {
					mensagemRetorno = tratarMensagemBot(update);
				} catch (Exception e) {
					mensagemRetorno = "Desculpe, n�o entendi... digite /ajuda para obter a lista de comandos conhecidos.";
				}
				bot.execute(new SendMessage(update.message().chat().id(), mensagemRetorno.toString()));
			}

		}
	}
}
 
开发者ID:pedrohnog,项目名称:Trabalhos-FIAP,代码行数:27,代码来源:Bot.java

示例2: createBot

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
private TelegramBot createBot(@NotNull TelegramSettings settings) {
  OkHttpClient.Builder builder = new OkHttpClient.Builder();
  if (settings.isUseProxy()) {
    builder.proxy(new Proxy(Proxy.Type.HTTP,
        new InetSocketAddress(settings.getProxyServer(), settings.getProxyPort())));
    if (!StringUtils.isEmpty(settings.getProxyUsername()) &&
        !StringUtils.isEmpty(settings.getProxyPassword())) {
      builder.proxyAuthenticator((route, response) -> {
        String credential =
            Credentials.basic(settings.getProxyUsername(), settings.getProxyPassword());
        return response.request().newBuilder()
            .header("Proxy-Authorization", credential)
            .build();
      });
    }
  }
  return TelegramBotAdapter.buildCustom(settings.getBotToken(), builder.build());
}
 
开发者ID:dancing-elf,项目名称:teamcity-telegram-plugin,代码行数:19,代码来源:TelegramBotManager.java

示例3: configure

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
@Override
public void configure(String propFilePath) throws IOException {
	InputStream is = getClass().getResourceAsStream("/" + propFilePath);

	/*
	 * Reading properties
	 */
	if (is != null) {
		BufferedInputStream bis = new BufferedInputStream(is);
		properties.load(bis);
		bot = TelegramBotAdapter.build(properties.getProperty("token"));
		BotServerTask.setUpdatesFetchDelay(Long.parseLong(properties.getProperty("updatesFetchDelay")));
		Task.setTaskDelay(Long.parseLong(properties.getProperty("taskDelay")));
		Task.setTaskDelay(Long.parseLong(properties.getProperty("taskDelay")));
		ModuleTask.setModuleTaskDelay(Long.parseLong(properties.getProperty("moduleTaskDelay")));
		ChatTask.setChatTaskDelay(Long.parseLong(properties.getProperty("chatTaskDelay")));
		ChatTask.setChatTaskTimeout(Long.parseLong(properties.getProperty("chatTaskTimeout")));
		bis.close();
	} else {
		throw new FileNotFoundException("The properties file is not found");
	}
}
 
开发者ID:MickevichYura,项目名称:grsu-schedule,代码行数:23,代码来源:BotServerTask.java

示例4: createBot

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
public static TelegramBot createBot(ConfigData configData)
{
	TelegramBot bot = null;
	if(configData.proxyConfig.enableProxy)
	{
		bot = TelegramBotAdapter.buildCustom(configData.telegramBotToken,setProxy(configData));
	}
	else
	{
		bot = TelegramBotAdapter.build(configData.telegramBotToken);
	}
	return bot;
}
 
开发者ID:XiLingHost,项目名称:tg-qq-trans,代码行数:14,代码来源:Initializer.java

示例5: onCreate

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    service = new PeripheralManagerService();
    tv = (TextView) findViewById(R.id.tv);
    Log.e(TAG, "GPIOs: " + service.getGpioList());
    initPins();

    tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
        }
    });

    bot = TelegramBotAdapter.build(BOT_TOKEN);
    GetUpdates getUpdates = new GetUpdates().limit(100).offset(0).timeout(10);
    bot.setUpdatesListener(new UpdatesListener() {
        @Override
        public int process(List<Update> updates) {
            for (Update update : updates) {
                Message msg = update.message();
                if (msg != null) {
                    String txt = msg.text();
                    tv.append("\n" + txt);
                    if (txt.trim().startsWith("LED")) {
                        Log.d(TAG, "LED COMMAND");
                        String[] data = txt.split(" ");
                        if (data[1].equalsIgnoreCase("blue")) {
                            Log.d(TAG, "Blue pin");
                            setPin(PIN_LED_BLUE);
                        } else if (data[1].equalsIgnoreCase("white")) {
                            Log.d(TAG, "White pin");
                            setPin(PIN_LED_WHITE);
                        }
                    } else if (txt.trim().startsWith("BEEP")) {
                        Log.d(TAG, "BEEZER COMMAND");
                        setPin(PIN_BEEZER);
                    }
                }
            }
            return UpdatesListener.CONFIRMED_UPDATES_ALL;
        }
    });

}
 
开发者ID:javadghane,项目名称:AndroidThingsWithTelegramBot,代码行数:50,代码来源:MainActivity.java

示例6: provideTelegramBot

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
protected TelegramBot provideTelegramBot() {
	final String telegramAccessToken = telegramConfigService.getAccessToken((SendMessage) null);
	final TelegramBot result = TelegramBotAdapter.build(telegramAccessToken);
	return result;
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:6,代码来源:TelegramWebhookImpl.java

示例7: provideTelegramBot

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
protected TelegramBot provideTelegramBot(final ReceiveMessage receiveMessage) {
	final String telegramAccessToken = telegramConfigService.getAccessToken(receiveMessage);
	final TelegramBot result = TelegramBotAdapter.build(telegramAccessToken);
	return result;
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:6,代码来源:TelegramReceivePayloadFactoryImpl.java

示例8: provideTelegramBot

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
protected TelegramBot provideTelegramBot(final SendMessage sendMessage) {
	final String telegramAccessToken = telegramConfigService.getAccessToken(sendMessage);
	final TelegramBot result = TelegramBotAdapter.build(telegramAccessToken);
	return result;
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:6,代码来源:AbstractTelegramSendRuleImpl.java

示例9: sendNotification

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
public void sendNotification(@NotNull Notification notification) {

        final StringBuilder message = new StringBuilder();
        String imContent = notification.getIMContent();

        if (!StringUtils.isEmpty(imContent) && resultsSummary != null) {
            if (resultsSummary.isSuccessful()) {
                message.append("\uD83D\uDE00 \uD83D\uDC4C ");
            } else {
                message.append("\uD83D\uDE31 \uD83D\uDE45\u200D♂️ ");
            }
            message.append(imContent).append(resultsSummary.getReasonSummary()).append("\n");

            List<String> authorsNames = resultsSummary.getUniqueAuthors().stream().map(Author::getFullName).collect(Collectors.toList());
            if (!authorsNames.isEmpty()) {
                message.append(" Responsible Users: ")
                        .append(String.join(", ", authorsNames))
                        .append("\n");
            }

            List<VariableSubstitution> variables = resultsSummary.getManuallyOverriddenVariables();
            if (!variables.isEmpty()) {
                message.append("Variables: \n");
                for (VariableSubstitution variable : variables) {
                    message.append(variable.getKey())
                            .append(": ")
                            .append(variable.getKey().contains("password") ? "******" :variable.getValue())
                            .append(" \n");
                }
            }

            List<String> labels = resultsSummary.getLabelNames();
            if (!labels.isEmpty()) {
                message.append("Labels: ")
                        .append(String.join(", ", labels))
                        .append("\n");
            }

            Set<LinkedJiraIssue> jiraIssues = resultsSummary.getRelatedJiraIssues();
            if (!jiraIssues.isEmpty()) {
                message.append("Issues: \n");
                for (LinkedJiraIssue issue : jiraIssues) {

                    if (issue.getJiraIssueDetails() == null) {
                        message.append(issue.getIssueKey());
                    } else {
                        message.append("<a href=\"")
                                .append(issue.getJiraIssueDetails().getDisplayUrl())
                                .append("\">")
                                .append(issue.getIssueKey())
                                .append("</a>")
                                .append(" - ")
                                .append(issue.getJiraIssueDetails().getSummary());
                    }
                    message.append("\n");
                }
            }
        }

        try {
            TelegramBot bot = TelegramBotAdapter.build(botToken);
            SendMessage request = new SendMessage(chatId, message.toString())
                    .parseMode(ParseMode.HTML);
            BaseResponse response = bot.execute(request);
            if (!response.isOk()) {
                log.error("Error using telegram API. error code: " + response.errorCode() + " message: " + response.description());
            } else {
                log.info("Success Telegram API message response: " + response.description() + " toString: " + response.toString());
            }
        } catch (RuntimeException e) {
            log.error("Error using telegram API: " + e.getMessage(), e);
        }
    }
 
开发者ID:leonoff,项目名称:bamboo-telegram-plugin,代码行数:74,代码来源:TelegramNotificationTransport.java

示例10: KursBot

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
public KursBot() throws IOException {
    Properties properties = new Properties();
    properties.load(new FileInputStream("local.properties"));
    String token = properties.getProperty("KURS_TOKEN");
    bot = TelegramBotAdapter.buildDebug(token);
}
 
开发者ID:pengrad,项目名称:java-telegram-bot-api,代码行数:7,代码来源:KursBot.java

示例11: AqivnBot

import com.pengrad.telegrambot.TelegramBotAdapter; //导入依赖的package包/类
public AqivnBot() throws IOException {
    Properties properties = new Properties();
    properties.load(new FileInputStream("local.properties"));
    token = properties.getProperty("AQIVN_TOKEN");
    bot = TelegramBotAdapter.buildDebug(token);
}
 
开发者ID:pengrad,项目名称:java-telegram-bot-api,代码行数:7,代码来源:AqivnBot.java


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