Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/ru/max/botapi/model/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@JsonSubTypes.Type(value = RequestGeoLocationButton.class, name = Button.REQUEST_GEO_LOCATION),
@JsonSubTypes.Type(value = RequestContactButton.class, name = Button.REQUEST_CONTACT),
@JsonSubTypes.Type(value = ChatButton.class, name = Button.CHAT),
@JsonSubTypes.Type(value = MessageButton.class, name = Button.MESSAGE),
})
@KnownInstance(ofClass = Button.class, discriminator = "type")
public class Button implements MaxSerializable {
Expand All @@ -51,12 +52,14 @@ public class Button implements MaxSerializable {
public static final String REQUEST_GEO_LOCATION = "request_geo_location";
public static final String REQUEST_CONTACT = "request_contact";
public static final String CHAT = "chat";
public static final String MESSAGE = "message";
public static final Set<String> TYPES = new HashSet<>(Arrays.asList(
CALLBACK,
LINK,
REQUEST_GEO_LOCATION,
REQUEST_CONTACT,
CHAT
CHAT,
MESSAGE // добавил новый тип кнопки
));

@NotNull
Expand Down Expand Up @@ -125,6 +128,7 @@ public interface Visitor {
void visit(RequestGeoLocationButton model);
void visit(RequestContactButton model);
void visit(ChatButton model);
void visit(MessageButton model);
void visitDefault(Button model);
}

Expand All @@ -134,6 +138,7 @@ public interface Mapper<T> {
T map(RequestGeoLocationButton model);
T map(RequestContactButton model);
T map(ChatButton model);
T map(MessageButton model);
T mapDefault(Button model);
}
}
2 changes: 1 addition & 1 deletion src/main/java/ru/max/botapi/model/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Message implements MaxSerializable {
private @Valid String url;

@JsonCreator
public Message(@JsonProperty("recipient") Recipient recipient, @JsonProperty("timestamp") Long timestamp, @JsonProperty("body") MessageBody body) {
public Message(@JsonProperty("recipient") Recipient recipient, @JsonProperty("timestamp") Long timestamp, @JsonProperty("message") MessageBody body) {
this.recipient = recipient;
this.timestamp = timestamp;
this.body = body;
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/ru/max/botapi/model/MessageButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ru.max.botapi.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Кнопка сообщение(самоделка).
*/
public class MessageButton extends Button implements MaxSerializable {


@JsonCreator
public MessageButton(@JsonProperty("text") String text) {
super(text);
}

@Override
public void visit(Visitor visitor) {
visitor.visit(this);
}

@Override
public <T> T map(Mapper<T> mapper) {
return mapper.map(this);
}

@JsonProperty("type")
@Override
public String getType() {
return Button.MESSAGE;
}

@Override
public String toString() {
return "MessageButton{"+ super.toString()
+ '}';
}
}
55 changes: 6 additions & 49 deletions src/test/java/ru/max/botapi/MaxIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,55 +36,7 @@
import ru.max.botapi.exceptions.APIException;
import ru.max.botapi.exceptions.AttachmentNotReadyException;
import ru.max.botapi.exceptions.ClientException;
import ru.max.botapi.model.Attachment;
import ru.max.botapi.model.AttachmentRequest;
import ru.max.botapi.model.AudioAttachment;
import ru.max.botapi.model.AudioAttachmentRequest;
import ru.max.botapi.model.BotInfo;
import ru.max.botapi.model.Button;
import ru.max.botapi.model.CallbackButton;
import ru.max.botapi.model.Chat;
import ru.max.botapi.model.ChatButton;
import ru.max.botapi.model.ChatList;
import ru.max.botapi.model.ChatStatus;
import ru.max.botapi.model.ChatType;
import ru.max.botapi.model.ContactAttachment;
import ru.max.botapi.model.ContactAttachmentRequest;
import ru.max.botapi.model.FileAttachment;
import ru.max.botapi.model.FileAttachmentRequest;
import ru.max.botapi.model.InlineKeyboardAttachment;
import ru.max.botapi.model.InlineKeyboardAttachmentRequest;
import ru.max.botapi.model.Intent;
import ru.max.botapi.model.LinkButton;
import ru.max.botapi.model.LinkedMessage;
import ru.max.botapi.model.LocationAttachment;
import ru.max.botapi.model.LocationAttachmentRequest;
import ru.max.botapi.model.Message;
import ru.max.botapi.model.MessageLinkType;
import ru.max.botapi.model.NewMessageBody;
import ru.max.botapi.model.NewMessageLink;
import ru.max.botapi.model.PhotoAttachment;
import ru.max.botapi.model.PhotoAttachmentRequest;
import ru.max.botapi.model.PhotoAttachmentRequestPayload;
import ru.max.botapi.model.PhotoTokens;
import ru.max.botapi.model.ReplyButton;
import ru.max.botapi.model.ReplyKeyboardAttachment;
import ru.max.botapi.model.ReplyKeyboardAttachmentRequest;
import ru.max.botapi.model.RequestContactButton;
import ru.max.botapi.model.RequestGeoLocationButton;
import ru.max.botapi.model.SendContactButton;
import ru.max.botapi.model.SendGeoLocationButton;
import ru.max.botapi.model.SendMessageButton;
import ru.max.botapi.model.SendMessageResult;
import ru.max.botapi.model.ShareAttachment;
import ru.max.botapi.model.ShareAttachmentRequest;
import ru.max.botapi.model.StickerAttachment;
import ru.max.botapi.model.StickerAttachmentRequest;
import ru.max.botapi.model.UploadType;
import ru.max.botapi.model.User;
import ru.max.botapi.model.UserIdsList;
import ru.max.botapi.model.VideoAttachment;
import ru.max.botapi.model.VideoAttachmentRequest;
import ru.max.botapi.model.*;
import ru.max.botapi.queries.AddMembersQuery;
import ru.max.botapi.queries.GetChatQuery;
import ru.max.botapi.queries.GetChatsQuery;
Expand Down Expand Up @@ -554,6 +506,11 @@ public void visit(ChatButton model) {
assertThat(model.getStartPayload(), is(cb.getStartPayload()));
}

@Override
public void visit(MessageButton model) {
assertThat(model, is(expectedButton));
}

@Override
public void visitDefault(Button model) {
assertThat(model, is(expectedButton));
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/ru/max/botapi/model/ButtonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public void shouldMap() {
new RequestGeoLocationButton("text geo"),
new CallbackButton("payload", "text"),
new ChatButton("title", "text").startPayload("startPayload").chatDescription("description").uuid(1234),
new RequestContactButton("request contact"));
new RequestContactButton("request contact"),
new MessageButton("text"));

for (Button button : buttons) {
AtomicReference<Button> mapped = button.map(new FailByDefaultButtonMapper<AtomicReference<Button>>() {
Expand Down Expand Up @@ -74,6 +75,11 @@ public AtomicReference<Button> map(RequestContactButton model) {
public AtomicReference<Button> map(ChatButton model) {
return new AtomicReference<>(button);
}

@Override
public AtomicReference<Button> map(MessageButton model) {
return new AtomicReference<>(button);
}
});

assertThat(mapped.get(), is(button));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public T map(ChatButton model) {
return shouldNotHappens();
}

@Override
public T map(MessageButton model) {
return shouldNotHappens();
}

@Override
public T mapDefault(Button model) {
return shouldNotHappens();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public void visit(ChatButton model) {
shouldNotHappens();
}

@Override
public void visit(MessageButton model) {
shouldNotHappens();
}

@Override
public void visitDefault(Button model) {
shouldNotHappens();
Expand Down