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


Java TelegramBot类代码示例

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


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

示例1: executarBot

import com.pengrad.telegrambot.TelegramBot; //导入依赖的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: apply

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Override
public void apply(final SendMessage sendMessage) {
	final ImageSendPayload imageSendPayload = sendMessage.getPayloadWithType(ImageSendPayload.class);

	final String title = imageSendPayload.getTitle();
	final String imageUrl = imageSendPayload.getImageUrl();
	final String recipient = sendMessage.getRecipient().getId();

	final SendPhoto sendPhotoTelegram = new SendPhoto(recipient, imageUrl);

	if (!Strings.isBlank(title)) {
		sendPhotoTelegram.caption(title);
	}

	LOG.info("sending image {} to recipient {}", sendPhotoTelegram, recipient);
	final TelegramBot client = provideTelegramBot(sendMessage);
	client.execute(sendPhotoTelegram);
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:19,代码来源:ImageRuleImpl.java

示例3: apply

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Override
public void apply(final SendMessage sendMessage) {
	final VideoSendPayload videoSendPayload = sendMessage.getPayloadWithType(VideoSendPayload.class);

	final String title = videoSendPayload.getTitle();
	final String videoUrl = videoSendPayload.getVideoUrl();
	final String recipient = sendMessage.getRecipient().getId();

	final SendVideo sendVideoTelegram = new SendVideo(recipient, videoUrl);

	if (!Strings.isBlank(title)) {
		sendVideoTelegram.caption(title);
	}

	LOG.info("sending video {} to recipient {}", sendVideoTelegram, recipient);
	final TelegramBot client = provideTelegramBot(sendMessage);
	client.execute(sendVideoTelegram);
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:19,代码来源:VideoRuleImpl.java

示例4: reloadIfNeeded

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
/**
 * Reload bot if settings changed
 * @param newSettings updated user settings
 */
public synchronized void reloadIfNeeded(@NotNull TelegramSettings newSettings) {
  if (Objects.equals(newSettings, settings)) {
    LOG.debug("Telegram bot token settings has not changed");
    return;
  }
  LOG.debug("New telegram bot token is received: " +
          StringUtil.truncateStringValueWithDotsAtEnd(newSettings.getBotToken(), 6));
  this.settings = newSettings;
  cleanupBot();
  if (settings.getBotToken() != null && !settings.isPaused()) {
    TelegramBot newBot = createBot(settings);
    addUpdatesListener(newBot);
    bot = newBot;
  }
}
 
开发者ID:dancing-elf,项目名称:teamcity-telegram-plugin,代码行数:20,代码来源:TelegramBotManager.java

示例5: createBot

import com.pengrad.telegrambot.TelegramBot; //导入依赖的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

示例6: sendSchedule

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Override
public void sendSchedule(TelegramBot bot, Message currentMessage, int day) {
	TimeUnit t = TimeUnit.MILLISECONDS;
	long daySeconds = t.convert(1L, TimeUnit.DAYS);
	DateFormat.DATE_FORMAT.applyPattern(DateFormat.DATE_FORMAT_PATTERN);	
	Date date = new Date(t.convert(currentMessage.date(), TimeUnit.SECONDS) + daySeconds * day);
	DayResponse groupSchedule = GetModels.getModels(Api.groupSchedule(settings.get(3)) + DateFormat.DATE_FORMAT.format(date),
			DayResponse.class);
	
	if(currentMessage.text().startsWith("/week")){
		for (Day daySchedule : groupSchedule.getDays()) {
			bot.sendMessage(currentMessage.chat().id(), daySchedule.toString(), ParseMode.Markdown, null, null, null);
		}
		return;
	}
	String sсhedule = groupSchedule.getDays().get(0).toString();
	bot.sendMessage(currentMessage.chat().id(), sсhedule.toString(), ParseMode.Markdown, null, null, null);

}
 
开发者ID:MickevichYura,项目名称:grsu-schedule,代码行数:20,代码来源:Student.java

示例7: sendSchedule

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Override
public void sendSchedule(TelegramBot bot, Message currentMessage, int day) {
	TimeUnit t = TimeUnit.MILLISECONDS;
	long daySeconds = t.convert(1L, TimeUnit.DAYS);
	DateFormat.DATE_FORMAT.applyPattern(DateFormat.DATE_FORMAT_PATTERN);
	Date date = new Date(t.convert(currentMessage.date(), TimeUnit.SECONDS) + daySeconds * day);
	DayResponse teacherSchedule = GetModels
			.getModels(Api.teacherSchedule(teacherId) + DateFormat.DATE_FORMAT.format(date), DayResponse.class);
	
	if(currentMessage.text().startsWith("/week")){
		for (Day daySchedule : teacherSchedule.getDays()) {
			bot.sendMessage(currentMessage.chat().id(), daySchedule.toString(), ParseMode.Markdown, null, null, null);
		}
		return;
	}
	String sсhedule = teacherSchedule.getDays().get(0).toString();
	bot.sendMessage(currentMessage.chat().id(), sсhedule.toString(), ParseMode.Markdown, null, null, null);

}
 
开发者ID:MickevichYura,项目名称:grsu-schedule,代码行数:20,代码来源:Teacher.java

示例8: createBot

import com.pengrad.telegrambot.TelegramBot; //导入依赖的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

示例9: main

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args)
{
	
	File configFile = new File("./config.json");
	ConfigData configData = new ConfigData();
	try
	{
		if(configFile.exists())
		{
			configData = config.ReadConfig.readConfig(configFile);
		}
		else
		{
			configFile.createNewFile();
			config.CreateConfigs.createConfigs(configFile);
			System.out.println("没有合适的配置文件,已创建空配置文件,请打开config.json进行配置。");
			System.exit(0);
		}
	}
	catch(IOException e)
	{
		e.printStackTrace();
	}
	TelegramBot bot = telegrambot.Initializer.createBot(configData);
	telegrambot.TelegramRunner telegramThread = new TelegramRunner(bot, configData);
	qqbot.QQRunner qqThread = new QQRunner(configData);
	telegramThread.run();
	qqThread.run();
	PluginsLoader pluginsLoader = new PluginsLoader(configData);
	pluginsLoader.run();
}
 
开发者ID:XiLingHost,项目名称:tg-qq-trans,代码行数:35,代码来源:Loader.java

示例10: init

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Inject
protected void init() {
	final String webhookUrl = telegramConfigService.getWebhookUrl((ReceiveMessage) null);

	if (Strings.isBlank(webhookUrl)) {
	} else {
		final SetWebhook request = new SetWebhook().url(webhookUrl);
		final TelegramBot bot = provideTelegramBot();
		bot.execute(request);
	}
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:12,代码来源:TelegramWebhookImpl.java

示例11: getFileUrl

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
protected String getFileUrl(final ReceiveMessage receiveMessage, final String fileId) {
	final TelegramBot bot = provideTelegramBot(receiveMessage);

	final GetFile getFile = new GetFile(fileId);
	final GetFileResponse response = bot.execute(getFile);
	final File file = response.file();
	final String url = bot.getFullFilePath(file);

	return url;
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:11,代码来源:TelegramReceivePayloadFactoryImpl.java

示例12: sendPhotoElement

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
protected void sendPhotoElement(final SendMessage sendMessage, final String recipient,
		final ListSendElement listSendElement) {
	final SendPhoto sendPhotoTelegram = new SendPhoto(recipient, listSendElement.getImageUrl());
	final String title = listSendElement.getTitle();

	if (!Strings.isBlank(title)) {
		sendPhotoTelegram.caption(title);
	}

	LOG.info("sending image {} to recipient {}", sendPhotoTelegram, recipient);
	final TelegramBot client = provideTelegramBot(sendMessage);
	client.execute(sendPhotoTelegram);
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:14,代码来源:ListRuleImpl.java

示例13: requestDescription

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Nullable
public BotInfo requestDescription(@NotNull TelegramSettings settings) {
  TelegramBot bot = createBot(settings);
  GetMeResponse response = bot.execute(new GetMe());
  User user = response.user();
  if (user == null) {
    return null;
  }
  return new BotInfo(user.firstName(), user.username());
}
 
开发者ID:dancing-elf,项目名称:teamcity-telegram-plugin,代码行数:11,代码来源:TelegramBotManager.java

示例14: addUpdatesListener

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
private void addUpdatesListener(TelegramBot bot) {
  bot.setUpdatesListener(updates -> {
    for (Update update: updates) {
      Message message = update.message();
      Long chatId = message.chat().id();
      SendMessage msg = new SendMessage(chatId,
          "Hello! Your chat id is '" + chatId + "'.\n" +
              "If you want to receive notifications about Teamcity events " +
              "please add this chat id in your Teamcity settings");
      bot.execute(msg);
    }
    return UpdatesListener.CONFIRMED_UPDATES_ALL;
  });
}
 
开发者ID:dancing-elf,项目名称:teamcity-telegram-plugin,代码行数:15,代码来源:TelegramBotManager.java

示例15: start

import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
public void start(TelegramBot bot, UpdatesListener listener, GetUpdates request) {
    this.bot = bot;
    this.listener = listener;
    getUpdates(request);
}
 
开发者ID:pengrad,项目名称:java-telegram-bot-api,代码行数:6,代码来源:UpdatesHandler.java


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