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


Java InlineKeyboardMarkup类代码示例

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


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

示例1: editMessageText

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
private JSONObject editMessageText(String chatId, Long messageId, String inlineMessageId, String text, ParseMode parseMode, boolean disableWebPagePreview, InlineReplyMarkup inlineReplyMarkup) {

        HttpResponse<String> response;
        JSONObject jsonResponse = null;

        try {
            MultipartBody requests = Unirest.post(getBotAPIUrl() + "editMessageText")
                    .field("text", text, "application/json; charset=utf8;")
                    .field("disable_web_page_preview", disableWebPagePreview);

            if(chatId != null) requests.field("chat_id", chatId, "application/json; charset=utf8;");
            if(messageId != null) requests.field("message_id", messageId);
            if(inlineMessageId != null) requests.field("inline_message_id", inlineMessageId, "application/json; charset=utf8;");
            if(parseMode != null) requests.field("parse_mode", parseMode.getModeName(), "application/json; charset=utf8;");
            if(inlineReplyMarkup != null) requests.field("reply_markup", GSON.toJson(inlineReplyMarkup, InlineKeyboardMarkup.class), "application/json; charset=utf8;");

            response = requests.asString();
            jsonResponse = Utils.processResponse(response);
        } catch (UnirestException e) {
            e.printStackTrace();
        }

        return jsonResponse;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:25,代码来源:TelegramBot.java

示例2: editMessageCaption

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
private JSONObject editMessageCaption(String chatId, Long messageId, String inlineMessageId, String caption, InlineReplyMarkup inlineReplyMarkup) {

        HttpResponse<String> response;
        JSONObject jsonResponse = null;

        try {
            MultipartBody requests = Unirest.post(getBotAPIUrl() + "editMessageCaption")
                    .field("caption", caption, "application/json; charset=utf8;");

            if(chatId != null) requests.field("chat_id", chatId, "application/json; charset=utf8;");
            if(messageId != null) requests.field("message_id", messageId);
            if(inlineMessageId != null) requests.field("inline_message_id", inlineMessageId, "application/json; charset=utf8;");
            if(inlineReplyMarkup != null) requests.field("reply_markup", GSON.toJson(inlineReplyMarkup, InlineKeyboardMarkup.class), "application/json; charset=utf8;");

            response = requests.asString();
            jsonResponse = Utils.processResponse(response);
        } catch (UnirestException e) {
            e.printStackTrace();
        }

        return jsonResponse;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:23,代码来源:TelegramBot.java

示例3: editMessageReplyMarkup

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
private JSONObject editMessageReplyMarkup(String chatId, Long messageId, String inlineMessageId, InlineReplyMarkup inlineReplyMarkup) {

        HttpResponse<String> response;
        JSONObject jsonResponse = null;

        try {
            MultipartBody requests = Unirest.post(getBotAPIUrl() + "editMessageReplyMarkup")
                    .field("reply_markup", GSON.toJson(inlineReplyMarkup, InlineKeyboardMarkup.class), "application/json; charset=utf8;");

            if(chatId != null) requests.field("chat_id", chatId, "application/json; charset=utf8;");
            if(messageId != null) requests.field("message_id", messageId);
            if(inlineMessageId != null) requests.field("inline_message_id", inlineMessageId, "application/json; charset=utf8;");

            response = requests.asString();
            jsonResponse = Utils.processResponse(response);
        } catch (UnirestException e) {
            e.printStackTrace();
        }

        return jsonResponse;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:22,代码来源:TelegramBot.java

示例4: processReplyContent

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
/**
 * This does generic processing of ReplyingOptions objects when sending a request to the API
 *
 * @param multipartBody     The MultipartBody that the ReplyingOptions content should be appended to
 * @param replyingOptions   The ReplyingOptions that were used in this request
 */
public static void processReplyContent(MultipartBody multipartBody, ReplyingOptions replyingOptions) {

    if (replyingOptions.getReplyTo() != 0)
        multipartBody.field("reply_to_message_id", String.valueOf(replyingOptions.getReplyTo()), "application/json; charset=utf8;");
    if (replyingOptions.getReplyMarkup() != null) {

        switch (replyingOptions.getReplyMarkup().getType()) {

            case FORCE_REPLY:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ForceReply.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_HIDE:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardHide.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_REMOVE:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardRemove.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_MARKUP:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardMarkup.class), "application/json; charset=utf8;");
                break;
            case INLINE_KEYBOARD_MARKUP:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), InlineKeyboardMarkup.class), "application/json; charset=utf8;");
                break;
        }
    }
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:33,代码来源:Utils.java

示例5: getButtons

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
public InlineKeyboardMarkup getButtons() {
    if (paginatedList.getPages() == 1) {
        return null;
    }

    LinkedList<InlineKeyboardButton> buttons = new LinkedList<>();

    if (paginatedList.getCurrentPage() > 1) {
        buttons.add(InlineKeyboardButton.builder()
                .callbackData(messageID.toString() + "|prev")
                .text("Previous").build());
    }

    buttons.add(InlineKeyboardButton.builder()
            .callbackData(messageID.toString() + "|ignore")
            .text("Page " + paginatedList.getCurrentPage() + "/" + paginatedList.getPages())
            .build());

    if (paginatedList.getCurrentPage() < paginatedList.getPages()) {
        buttons.add(InlineKeyboardButton.builder()
                .callbackData(messageID.toString() + "|next")
                .text("Next").build());
    }

    return InlineKeyboardMarkup.builder().addRow(buttons).build();
}
 
开发者ID:stuntguy3000,项目名称:RedditLiveBot,代码行数:27,代码来源:PaginatedMessage.java

示例6: onInlineQueryReceived

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
@Override
public void onInlineQueryReceived(InlineQueryReceivedEvent event) {

    //This gets the query text from the inline query
    String queryString = event.getQuery().getQuery();

    if(event.getQuery().getQuery().length() == 0 || event.getQuery().getQuery().length() > 200) return;

    //This retrieves the senders username if they have one, otherwise gets their user ID
    String senderName = !event.getQuery().getSender().getUsername().equals("") ? event.getQuery().getSender().getUsername() : String.valueOf(event.getQuery().getSender().getId());

    //This simply prints out a debug message to console of the senders username/ID and their query
    System.out.println(senderName + " - " + event.getQuery().getQuery());

    //This generates a UUID in order to identify the specific spoiler later
    UUID uuid = UUID.randomUUID();
    //This stores the spoiler against the UUID in a Map to recall later
    possibleSpoilers.put(uuid, new Spoiler(queryString));

    //This creates an InlineQueryResponse object, including some results that we generate.
    //The is_personal(true) means that results will be unique which isn't require but is better
    //due to the UUIDs that are used. cache_time(0) means that the results will never be cached
    //by telegrams servers. You can change the time accordingly to suit your needs.
    event.getQuery().answer(telegramBot, InlineQueryResponse.builder()
            .results(InlineQueryResultArticle.builder().id("0" + uuid.toString()).replyMarkup(InlineKeyboardMarkup.builder().addRow(InlineKeyboardButton.builder().text("View Spoiler!").callbackData(uuid.toString()).build()).build()).inputMessageContent(InputTextMessageContent.builder().messageText("Mild Spoiler Alert! Click below to view!").build()).description(queryString).title("Mild Spoiler").thumbUrl(mildWarning).build(),
                    InlineQueryResultArticle.builder().id("1" + uuid.toString()).replyMarkup(InlineKeyboardMarkup.builder().addRow(InlineKeyboardButton.builder().text("View Spoiler!").callbackData(uuid.toString()).build()).build()).inputMessageContent(InputTextMessageContent.builder().messageText("❕Moderate Spoiler Alert! Click below to view❕").build()).description(queryString).title("Moderate Spoiler").thumbUrl(moderateWarning).build(),
                    InlineQueryResultArticle.builder().id("2" + uuid.toString()).replyMarkup(InlineKeyboardMarkup.builder().addRow(InlineKeyboardButton.builder().text("View Spoiler!").callbackData(uuid.toString()).build()).build()).inputMessageContent(InputTextMessageContent.builder().messageText("❗️Huge Spoiler Alert Click below to view❗️").build()).description(queryString).title("Huge Spoiler").thumbUrl(hugeWarning).build(),
                    InlineQueryResultArticle.builder().id("3" + uuid.toString()).replyMarkup(InlineKeyboardMarkup.builder().addRow(InlineKeyboardButton.builder().text("View Spoiler!").callbackData(uuid.toString()).build()).build()).inputMessageContent(InputTextMessageContent.builder().messageText("‼️Insane Spoiler Alert Click below to confirm, and click again to view‼️").build()).description(queryString).title("Insane Spoiler, requires two clicks to view!").thumbUrl(insaneWarning).build()
            ).cache_time(0)
            .is_personal(true)
            //.switch_pm_text("Switch to PM!")
            .build()
    );
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:35,代码来源:InlineSpoilerListener.java

示例7: toKeyboard

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
/**
 * Converts rows to the inline keyboard markup used by the Telegram API
 * @return keyboard markup
 */
public InlineKeyboardMarkup toKeyboard() {
    InlineKeyboardMarkup.InlineKeyboardMarkupBuilder builder =
            InlineKeyboardMarkup.builder();

    if (rows.isEmpty()) {
        return null;
    }

    rows.stream().map(InlineMenuRow::toButtons).forEach(builder::addRow);
    return builder.build();
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:16,代码来源:InlineMenu.java

示例8: postNewLiveThread

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
/**
 * Posts a new live thread to the admin chat
 *
 * @param redditThread SubredditChildrenData the data to be posted
 * @param threadID     String the id of the thread
 */
public void postNewLiveThread(SubredditChildrenData redditThread, String threadID) {
    Message message = updateMessages.get(threadID);
    String lastMessage = lastMessages.get(threadID);

    String threadInformation = "*Reddit Live Thread*\n\n" +
            "*Thread ID:* " + threadID + "\n" +
            "*Thread URL:* https://reddit.com/live/" + threadID + "\n" +
            "*Thread Title:* " + redditThread.getTitle() + "\n" +
            "*Score:* " + redditThread.getScore() + "\n";

    List<InlineKeyboardButton> buttons = new ArrayList<>();

    buttons.add(InlineKeyboardButton.builder()
            .callbackData("f," + threadID)
            .text("Follow (Normal)").build());

    buttons.add(InlineKeyboardButton.builder()
            .callbackData("fS," + threadID)
            .text("Follow (Silent)").build());

    if (lastMessage != null && lastMessage.equals(threadInformation)) {
        return;
    }

    if (message == null) {
        message = adminChat.sendMessage("Loading new live thread...");
    }

    message = TelegramHook.getBot().editMessageText(message, threadInformation,
            ParseMode.MARKDOWN, false, InlineKeyboardMarkup.builder().addRow(buttons).build());

    updateMessages.put(threadID, message);
    lastMessages.put(threadID, threadInformation);
}
 
开发者ID:stuntguy3000,项目名称:RedditLiveBot,代码行数:41,代码来源:AdminControlHandler.java

示例9: processCommand

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
public void processCommand(CommandMessageReceivedEvent event) {
    StringBuilder commandHelp = new StringBuilder();

    if (event.getArgs().length > 0) {
        if (event.getArgs()[0].equalsIgnoreCase("subscribe")) {
            new SubscribeCommand().processCommand(event);
            return;
        }
    }

    commandHelp.append("*Welcome to RedditLiveBot*\n" +
            "Created by @stuntguy3000, this bot allows you to stay up to date to trending RedditLive threads. " +
            "All the content is monitored constantly by our administration team, ensuring the content is of a high standard.\n\n" +
            "To begin, type /subscribe in a group chat, or join @RedditLive to stay up to date!\n\n" +
            "*Command help:*\n" +
            "/subscribe - Subscribe to updates from @RedditLive\n" +
            "/unsubscribe - Unsubscribe to updates from @RedditLive\n" +
            "/version - Show bot version information, and provide a link to the source code.");

    List<InlineKeyboardButton> buttons = new ArrayList<>();

    buttons.add(InlineKeyboardButton.builder()
            .text(Emoji.GREEN_BOX_TICK.getText() + " Subscribe")
            .callbackData("usrSubscribe:" + event.getChat().getId())
            .build());

    SendableTextMessage sendableTextMessage = SendableTextMessage.builder()
            .message(commandHelp.toString())
            .parseMode(ParseMode.MARKDOWN)
            .replyMarkup(InlineKeyboardMarkup.builder().addRow(buttons).build())
            .build();

    event.getChat().sendMessage(sendableTextMessage);
}
 
开发者ID:stuntguy3000,项目名称:RedditLiveBot,代码行数:35,代码来源:HelpCommand.java

示例10: getDashboardKeyboardMarkup

import pro.zackpollard.telegrambot.api.keyboards.InlineKeyboardMarkup; //导入依赖的package包/类
/**
 * Generate the keyboard markup for a Chat
 * <p>The admin dashboard is a simple GUI to control basic functions of the bot</p>
 *
 * @param chat Chat the chat where the message will be sent
 *
 * @return InlineKeyboardMarkup the generated markup
 */
public InlineKeyboardMarkup getDashboardKeyboardMarkup(Chat chat) {
    RedditHandler redditHandler = RedditLiveBot.instance.getRedditHandler();
    List<InlineKeyboardButton> buttons = new ArrayList<>();

    // Current bot status
    if (redditHandler.getCurrentLiveThread() != null) {
        buttons.add(InlineKeyboardButton.builder()
                .text("Unfollow current thread").callbackData(
                        AdminInlineCommandType.STOP_FOLLOW.getCommandID() + "#" + chat.getId())
                .build());
    } else {
        buttons.add(InlineKeyboardButton.builder()
                .text("Follow a thread").callbackData(
                        AdminInlineCommandType.START_FOLLOW.getCommandID() + "#" + chat.getId())
                .build());
    }

    // Subscription data
    int count = RedditLiveBot.instance.getSubscriptionHandler().getSubscriptions().size();
    buttons.add(InlineKeyboardButton.builder()
            .text("View Subscriptions (" + count + ")").callbackData(
                    AdminInlineCommandType.SHOW_SUBS.getCommandID() + "#" + chat.getId())
            .build());

    // Toggle Debug
    buttons.add(InlineKeyboardButton.builder()
            .text("Enable Debug").callbackData(
                    AdminInlineCommandType.ENABLE_DEBUG.getCommandID() + "#" + chat.getId())
            .build());

    buttons.add(InlineKeyboardButton.builder()
            .text("Disable Debug").callbackData(
                    AdminInlineCommandType.DISABLE_DEBUG.getCommandID() + "#" + chat.getId())
            .build());

    // Broadcast Message
    buttons.add(InlineKeyboardButton.builder()
            .text("Broadcast a message").callbackData(
                    AdminInlineCommandType.BROADCAST.getCommandID() + "#" + chat.getId())
            .build());

    // Restart bot
    buttons.add(InlineKeyboardButton.builder()
            .text("Restart the bot").callbackData(
                    AdminInlineCommandType.RESTART.getCommandID() + "#" + chat.getId())
            .build());

    // Build the final message
    InlineKeyboardMarkup.InlineKeyboardMarkupBuilder markup = InlineKeyboardMarkup.builder();

    List<InlineKeyboardButton> rows = new ArrayList<>();
    for (InlineKeyboardButton keyboardButton : buttons) {
        rows.add(keyboardButton);

        if (rows.size() == 2) {
            markup.addRow(rows);
            rows.clear();
        }
    }

    return markup.build();
}
 
开发者ID:stuntguy3000,项目名称:RedditLiveBot,代码行数:71,代码来源:AdminControlHandler.java


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