Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

message_new: CallbackApi.parse() ожидает структуру json отличную от описанной в схеме #272

Open
rurikovich opened this issue Dec 30, 2022 · 0 comments

Comments

@rurikovich
Copy link

rurikovich commented Dec 30, 2022

приходит json вида:
`
{
"group_id" : <group_id>,
"type" : "message_new",
"event_id" : "<event_id>",
"v" : "5.131",
"object" : {
"message" : {
"date" : 1672387895,
"from_id" : <from_id>,
"id" : ,
"out" : 0,
"attachments" : [
],
"conversation_message_id" : <conversation_message_id>,
"fwd_messages" : [
],
"important" : false,
"is_hidden" : false,
"peer_id" : 8342610,
"random_id" : 0,
"text" : "ывц3к4ас уавау"
},
"client_info" : {
"button_actions" : [
"text",
"vkpay",
"open_app",
"location",
"open_link",
"open_photo",
"callback",
"intent_subscribe",
"intent_unsubscribe"
],
"keyboard" : true,
"inline_keyboard" : true,
"carousel" : true,
"lang_id" : 0
}
}
}

`

В sdk парсинг джейсона в класс происходит в 2 этапа:

  1. сначала парсим в класс CallbackMessage

`public class CallbackMessage {

@SerializedName("type")
private Events type;

@SerializedName("group_id")
private Integer groupId;

@SerializedName("object")
private JsonObject object;

@SerializedName("secret")
private String secret;

...
}

`

где object с типом JsonObject получает значение:

{ "message" : { "date" : 1672387895, "from_id" : <from_id>, "id" : <id>, "out" : 0, "attachments" : [ ], "conversation_message_id" : <conversation_message_id>, "fwd_messages" : [ ], "important" : false, "is_hidden" : false, "peer_id" : 8342610, "random_id" : 0, "text" : "ывц3к4ас уавау" }, "client_info" : { "button_actions" : [ "text", "vkpay", "open_app", "location", "open_link", "open_photo", "callback", "intent_subscribe", "intent_unsubscribe" ], "keyboard" : true, "inline_keyboard" : true, "carousel" : true, "lang_id" : 0 } }

и имеет структуру

[
"message" : {...},
 "client_info" : {...}
]
  1. этап 2
    мы пытаемся попарсить

[ "message" : {...}, "client_info" : {...} ]

в класс

`
/**

  • Message object
    */
    public class Message implements Validable {
    @SerializedName("action")
    private MessageAction action;

    /**

    • Only for messages from community. Contains user ID of community admin, who sent this message.
      */
      @SerializedName("admin_author_id")
      private Integer adminAuthorId;

    @SerializedName("attachments")
    private List attachments;

    /**

    • Unique auto-incremented number for all messages with this peer
      */
      @SerializedName("conversation_message_id")
      private Integer conversationMessageId;

    /**

    • Date when the message has been sent in Unixtime
      */
      @SerializedName("date")
      @required
      private Integer date;

    /**

    • Is it an deleted message
      */
      @SerializedName("deleted")
      private BoolInt deleted;

    /**

    • Message author's ID
      */
      @SerializedName("from_id")
      private Integer fromId;

    /**

    • Forwarded messages
      */
      @SerializedName("fwd_messages")
      private List fwdMessages;

    @SerializedName("geo")
    private Geo geo;

    /**

    • Message ID
      */
      @SerializedName("id")
      @required
      private Integer id;

    /**

    • Is it an important message
      */
      @SerializedName("important")
      private Boolean important;

    @SerializedName("is_hidden")
    private Boolean isHidden;

    /**

    • this message is cropped for bot
      */
      @SerializedName("is_cropped")
      private Boolean isCropped;

    @SerializedName("keyboard")
    private Keyboard keyboard;

    /**

    • Members number
      */
      @SerializedName("members_count")
      private Integer membersCount;

    /**

    • Information whether the message is outcoming
      */
      @SerializedName("out")
      @required
      private BoolInt out;

    @SerializedName("payload")
    private String payload;

    /**

    • Peer ID
      */
      @SerializedName("peer_id")
      private Integer peerId;

    /**

    • ID used for sending messages. It returned only for outgoing messages
      */
      @SerializedName("random_id")
      private Integer randomId;

    @SerializedName("ref")
    private String ref;

    @SerializedName("ref_source")
    private String refSource;

    @SerializedName("reply_message")
    private ForeignMessage replyMessage;

    /**

    • Message text
      */
      @SerializedName("text")
      @required
      private String text;

    /**

    • Date when the message has been updated in Unixtime
      */
      @SerializedName("update_time")
      private Integer updateTime;

    /**

    • Was the audio message inside already listened by you
      */
      @SerializedName("was_listened")
      private Boolean wasListened;

    /**

    • Date when the message has been pinned in Unixtime
      */
      @SerializedName("pinned_at")
      private Integer pinnedAt;

    /**

    • Is silent message, push without sound
      */
      @SerializedName("is_silent")
      private Boolean isSilent;

    ...

    }

`

и получаем null

тк есть лишний объект "client_info" : {...}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant