Skip to content

Release 1.0.28-beta

Compare
Choose a tag to compare
@yvasyliev yvasyliev released this 03 Nov 21:25
· 541 commits to master since this release
ed447a8
<dependency>
    <groupId>com.github.yvasyliev</groupId>
    <artifactId>java-vk-bots-longpoll-api</artifactId>
    <version>1.0.28-beta</version>
</dependency>

Keyboard support added!

1. Buttons example

Button button1 = new Button()
        .setAction(new Button.TextAction().setLabel("Positive button"))
        .setColor(Button.ButtonColor.POSITIVE);
Button button2 = new Button()
        .setAction(new Button.TextAction().setLabel("Negative button"))
        .setColor(Button.ButtonColor.NEGATIVE);
Button button3 = new Button()
        .setAction(new Button.TextAction().setLabel("Primary button"))
        .setColor(Button.ButtonColor.PRIMARY);
Button button4 = new Button()
        .setAction(new Button.TextAction().setLabel("Secondary button"))
        .setColor(Button.ButtonColor.SECONDARY);

List<Button> row1 = Arrays.asList(button1, button2);
List<Button> row2 = Arrays.asList(button3, button4);

Keyboard keyboard = new Keyboard().setButtons(Arrays.asList(row1, row2));

new MessagesSend(this)
        .setPeerId(message.getPeerId())
        .setMessage("Buttons example")
        .setKeyboard(keyboard)
        .execute();

Result:

buttons example

2. Callback button example

@Override
public void onMessageNew(MessageNewEvent messageNewEvent) {
    try {
        Message message = messageNewEvent.getMessage();
        Button button = new Button()
                .setAction(new Button.CallbackAction().setLabel("Click me"))
                .setColor(Button.ButtonColor.POSITIVE);
        Keyboard keyboard = new Keyboard()
                .setButtons(Arrays.asList(Arrays.asList(button)))
                .setInline(true);

        new MessagesSend(this)
                .setPeerId(111)
                .setMessage("A Callback button example")
                .setKeyboard(keyboard)
                .execute();
    } catch (ApiHttpException e) {
        e.printStackTrace();
    }
}

@Override
public void onMessageEvent(MessageEvent messageEvent) {
    try {
        new MessagesSendEventAnswer(this)
                .setUserId(messageEvent.getUserId())
                .setPeerId(messageEvent.getPeerId())
                .setEventId(messageEvent.getEventId())
                .setEventData(new Button.ShowSnackbar().setText("Hi there!"))
                .execute();
    } catch (ApiHttpException e) {
        e.printStackTrace();
    }
}

Result:

Callback button example

3. Carousel example

Button button1 = new Button().setAction(new Button.TextAction().setLabel("button1"));
Template.Carousel.Element element1 = new Template.Carousel.Element()
        .setTitle("Title1")
        .setDescription("Description1")
        .setButtons(Arrays.asList(button1));

Button button2 = new Button().setAction(new Button.TextAction().setLabel("button2"));
Template.Carousel.Element element2 = new Template.Carousel.Element()
        .setTitle("Title2")
        .setDescription("Description2")
        .setButtons(Arrays.asList(button2));

Template.Carousel carousel = new Template.Carousel().setElements(Arrays.asList(element1, element2));

new MessagesSend(this)
        .setPeerId(111)
        .setMessage("Carousel example")
        .setTemplate(carousel)
        .execute();

Result:

Carousel example