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


Java GetUpdates类代码示例

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


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

示例1: executarBot

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

import com.pengrad.telegrambot.request.GetUpdates; //导入依赖的package包/类
@Override
public void run()
{
	System.out.println("TelegramBot创建成功");
	GetUpdates getUpdates = new GetUpdates().limit(100).offset(0).timeout(0);
	GetUpdatesResponse updatesResponse = bot.execute(getUpdates);
	Message message = null;
	while(true)
	{
		List<Update> updates = updatesResponse.updates();
		for(Update update : updates)
		{
			message = update.message();
			receiveMessages.offer(message.text());
		}
	}

}
 
开发者ID:XiLingHost,项目名称:tg-qq-trans,代码行数:19,代码来源:TelegramRunner.java

示例3: onCreate

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

示例4: setUpdatesListener

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

示例5: start

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

示例6: main

import com.pengrad.telegrambot.request.GetUpdates; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    Properties properties = new Properties();
    properties.load(new FileInputStream("local.properties"));
    TelegramBot bot = TelegramBotAdapter.build(properties.getProperty("TEST_TOKEN"));

    GetUpdatesResponse updatesResponse;
    int j = 0;
    while (true) {
        try {
            updatesResponse = bot.execute(new GetUpdates().offset(j).limit(100).timeout(20));
            List<Update> updates = updatesResponse.updates();
            for (int z = 0; z < updates.size(); z++) {
                j = updates.get(z).updateId() + 1;
                Message message = updates.get(z).message();
                //
                Chat chat = message.chat();
                User user = message.from();
                //String mes=message.text();

                // Base64.getEncoder().encodeToString(s.getBytes(StandardCharsets.UTF_8));
                if (message.text() != null) {
                    System.out.println("New message: " + message.text() + " id: " + message.messageId() + " from " + chat);
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:pengrad,项目名称:java-telegram-bot-api,代码行数:31,代码来源:TestLoopGetUpdates.java


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