• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Chat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setupContext

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
public static void setupContext(Message message) {
	User user = message.getFrom();
	Chat chat = message.getChat();
	Long chatId = chat.getId();

	if (!tgUserContexts.containsKey(chatId)) {
		TgContext value = new TgContext();
		value.setUser(user);
		value.setChat(chat);
		tgUserContexts.put(chatId, value);
	}

	TgContext tgContext = tgUserContexts.get(chatId);

	tgContextThreadLocal.set(tgContext);
}
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:17,代码来源:TgContextHolder.java


示例2: onUpdateReceived

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
    if (update.getMessage() != null) {
        Long chatId = update.getMessage().getChatId();
        String text = update.getMessage().getText();

        if ("/start".equals(text)) {
            send(chatId, "Hello, You can get an id for sending or forwarding messages");
        }

        send(chatId, "Your telegram id: " + chatId);

        Chat forwardFromChat = update.getMessage().getForwardFromChat();
        if (forwardFromChat != null) {
            send(chatId, "Message source id: " + update.getMessage().getForwardFromChat().getId());
        }
    }
}
 
开发者ID:junbaor,项目名称:telegram-bot,代码行数:19,代码来源:GetIdHandler.java


示例3: execute

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


示例4: execute

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


示例5: execute

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


示例6: execute

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

    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:comdata,项目名称:HomeAutomation,代码行数:22,代码来源:HelpCommand.java


示例7: deserializeResponse

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@Override
public Chat deserializeResponse(String answer) throws TelegramApiRequestException {
    try {
        ApiResponse<Chat> result = OBJECT_MAPPER.readValue(answer,
                new TypeReference<ApiResponse<Chat>>(){});
        if (result.getOk()) {
            return result.getResult();
        } else {
            throw new TelegramApiRequestException("Error getting chat", result);
        }
    } catch (IOException e) {
        throw new TelegramApiRequestException("Unable to deserialize response", e);
    }
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:15,代码来源:GetChat.java


示例8: assertPrivateChat

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
private void assertPrivateChat(Chat chat) {
    Assert.assertNotNull(chat);
    Assert.assertEquals(Long.valueOf(1111111), chat.getId());
    Assert.assertTrue(chat.isUserChat());
    Assert.assertEquals("Test Lastname", chat.getLastName());
    Assert.assertEquals("Test Firstname", chat.getFirstName());
    Assert.assertEquals("Testusername", chat.getUserName());
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:9,代码来源:TestDeserialization.java


示例9: execute

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

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

    String userName = chat.getUserName();
    if (userName == null || userName.isEmpty()) {
        userName = user.getFirstName() + " " + user.getLastName();
    }

    StringBuilder messageTextBuilder = new StringBuilder("Hello ").append(userName);
    if (arguments != null && arguments.length > 0) {
        messageTextBuilder.append("\n");
        messageTextBuilder.append("Thank you so much for your kind words:\n");
        messageTextBuilder.append(String.join(" ", arguments));
    }

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

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


示例10: getChat

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
public Chat getChat() {
	return chat;
}
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:4,代码来源:TgContext.java


示例11: setChat

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
public void setChat(Chat chat) {
	this.chat = chat;
	this.chatId = chat.getId();
}
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:5,代码来源:TgContext.java


示例12: assertChannelChat

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
private void assertChannelChat(Chat chat) {
    Assert.assertNotNull(chat);
    Assert.assertEquals(Long.valueOf(-10000000000L), chat.getId());
    Assert.assertTrue(chat.isChannelChat());
    Assert.assertEquals("Test channel", chat.getTitle());
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:7,代码来源:TestDeserialization.java


示例13: execute

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@Override
public final void execute(AbsSender absSender, User user, Chat chat, String[] arguments) {
}
 
开发者ID:rubenlagus,项目名称:TelegramBots,代码行数:4,代码来源:DefaultBotCommand.java


示例14: execute

import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
/**
 * Execute the command
 *
 * @param absSender absSender to send messages over
 * @param user      the user who sent the command
 * @param chat      the chat, to be able to send replies
 * @param arguments passed arguments
 */
public abstract void execute(AbsSender absSender, User user, Chat chat, String[] arguments);
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:10,代码来源:BotCommand.java


示例15: execute

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

	String userId = user.getId().toString();

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

	LogManager.getLogger(this.getClass()).info("Request from user: " + String.valueOf(user.getId()));

	if (arguments != null && arguments.length == 1) {

		if (authSecret.equals(arguments[0])) {

			answer.setText("user authenticated: " + user.getId());

			List result = em.createQuery("select u from TelegramUser u where u.userId=:userId")
					.setParameter("userId", userId).getResultList();

			if (result == null || result.isEmpty()) {

				em.getTransaction().begin();

				TelegramUser telegramUser = new TelegramUser();

				telegramUser.setUserId(userId);
				telegramUser.setAuthenticated(true);

				em.persist(telegramUser);

				em.getTransaction().commit();
			}

		} else {
			answer.setText("wrong credentials");
		}

	} else {
		answer.setText("not authenticated");
	}

	try {
		absSender.sendMessage(answer);
	} catch (TelegramApiException e) {
		BotLogger.error(LOGTAG, e);
	}

}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:49,代码来源:AuthenticateCommand.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Path类代码示例发布时间:2022-05-22
下一篇:
Java PvmProcessInstance类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap