Vk api на java. Как сделать кнопки
Вот код:
public class Bot {
public static void main(String[] args) throws ClientException, ApiException, InterruptedException {
TransportClient transportClient = new HttpTransportClient();
VkApiClient vk = new VkApiClient(transportClient);
Random random = new Random();
Keyboard keyboard = new Keyboard();
List
> allKey = new ArrayList<>();
List
line1.add(new KeyboardButton()).setAction(new KeyboardButtonAction().setLabel("Привет").setType(KeyboardButtonActionType.TEXT).setColor(KeyboardButtonColor.POSITIVE));
line1.add(new KeyboardButton()).setAction(new KeyboardButtonAction().setLabel("Кто я?").setType(KeyboardButtonActionType.TEXT).setColor(KeyboardButtonColor.POSITIVE));
keyboard.setButtons(allKey);
GroupActor actor = new GroupActor(211045078, "Key");
Integer ts = vk.messages().getLongPollServer(actor).execute().getTs();
while(true){
MessagesGetLongPollHistoryQuery historyQuery = vk.messages().getLongPollHistory(actor).ts(ts);
List
if(!messages.isEmpty()){
messages.forEach(message -> {
System.out.println(message.toString());
try {
if (message.getText().equals("Привет")){
vk.messages().send(actor).message("Привет").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
}
else if (message.getText().equals("Кто я?")) {
vk.messages().send(actor).message("Ты хороший человек.").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
}
else if (message.getText().equals("Кнопки")){
vk.messages().send(actor).message("А вот и они").userId(message.getFromId()).randomId(random.nextInt(10000)).keyboard(keyboard).execute();
}
else {
vk.messages().send(actor).message("Я тебя не понял").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
}
}catch (ApiException | ClientException e) {e.printStackTrace();}
});
}
ts = vk.messages().getLongPollServer(actor).execute().getTs();
Thread.sleep(500);
}
}
}
И на строке---
line1.add(new KeyboardButton()).setAction(new KeyboardButtonAction().setLabel("Привет").setType(KeyboardButtonActionType.TEXT).setColor(KeyboardButtonColor.POSITIVE));
Выдаёт ошибку 'setType(com.vk.api.sdk.objects.messages.TemplateActionTypeNames)' in 'com.vk.api.sdk.objects.messages.KeyboardButtonAction' cannot be applied to '(com.vk.api.sdk.objects.messages.KeyboardButtonActionType)'
Как это решить? Для java докуменация просто идиотия:|
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
- Akiv Doros
- Nov. 11, 2024, 10:58 p.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:50points,
- Rating points-4
- molni99
- Oct. 26, 2024, 8:37 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
- molni99
- Oct. 26, 2024, 8:29 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:20points,
- Rating points-10
Првиет
line1.add(new KeyboardButton().setAction(new KeyboardButtonAction().setLabel("Текст кнопки").setType(TemplateActionTypeNames.TEXT)).setColor(KeyboardButtonColor.POSITIVE));
А вообще там градл уже другой
plugins {
id 'java'
id 'application'
}
apply plugin: 'java'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
}
mainClassName = 'class.name'
dependencies {
implementation 'com.vk.api:sdk:1.0.7'
}