Class Message


  • public class Message
    extends Object
    Message object for both (received and sent) messages
    • Constructor Detail

      • Message

        public Message()
        Constructor for sent message
      • Message

        public Message​(Client client,
                       Integer messageId,
                       Integer flags,
                       Integer peerId,
                       Integer timestamp,
                       String text,
                       org.json.JSONObject attachments,
                       Integer randomId)
        Constructor for received message
        Parameters:
        client - client
        messageId - message id
        flags - flags
        peerId - peer id
        timestamp - timestamp
        text - message text
        attachments - message attachments
        randomId - random id
    • Method Detail

      • from

        public Message from​(Client client)
        Your client with id, access token
        Parameters:
        client - client
        Returns:
        this
      • to

        public Message to​(Integer peerId)
        ID of target dialog
        Parameters:
        peerId - target
        Returns:
        this
      • sticker

        public Message sticker​(Integer id)
        ID of sticker, only for user tokens
        Parameters:
        id - sticker id
        Returns:
        this
      • forwardedMessages

        public Message forwardedMessages​(Object... ids)
        IDs of forwarded messages
        Parameters:
        ids - message ids
        Returns:
        this
      • text

        public Message text​(Object text)
        Message text
        Parameters:
        text - message content
        Returns:
        this
      • title

        public Message title​(Object title)
        Message title (bold text)
        Parameters:
        title - message title
        Returns:
        this
      • attachments

        public Message attachments​(String... attachments)
        Message attachments
        Parameters:
        attachments - attachments
        Returns:
        this
      • randomId

        public Message randomId​(Integer randomId)
        Message random_id
        Parameters:
        randomId - random
        Returns:
        this
      • photo

        public Message photo​(String photo)
        Synchronous adding photo to the message
        Parameters:
        photo - String URL, link to vk doc or path to file
        Returns:
        this
      • doc

        public Message doc​(String doc,
                           DocTypes typeOfDoc)
        Synchronous adding doc to the message
        Parameters:
        doc - String URL, link to vk doc or path to file
        typeOfDoc - Type of doc, 'audio_message' or 'graffiti' ('doc' as default)
        Returns:
        this
      • docFromBytes

        public Message docFromBytes​(byte[] docBytes,
                                    DocTypes typeOfDoc,
                                    String fileNameField)
      • doc

        public Message doc​(String doc)
        Synchronous adding doc to the message
        Parameters:
        doc - String URL, link to vk doc or path to file
        Returns:
        this
      • photoAsync

        public Message photoAsync​(String photo)
        Attach photo to message

        Works slower that sync photo adding, but will be called from execute

        Parameters:
        photo - Photo link: url, from disk or already uploaded to VK as photo{owner_id}_{id}
        Returns:
        this
      • uploadPhoto

        public void uploadPhoto​(String photo,
                                Callback<Object> callback)
        Async uploading photos
        Parameters:
        photo - Photo link: url, from disk or already uploaded to VK as photo{owner_id}_{id}
        callback - callback
      • uploadDoc

        public void uploadDoc​(org.json.JSONObject doc,
                              Callback<Object> callback)
        Async uploading doc
        Parameters:
        doc - Doc link: url, from disk or already uploaded to VK as doc{owner_id}_{id}
        callback - callback
      • docAsync

        public Message docAsync​(String doc,
                                DocTypes type)
        Attach doc to message
        Parameters:
        doc - Doc link: url, from disk or already uploaded to VK as doc{owner_id}_{id}
        type - type
        Returns:
        this
      • docAsync

        public Message docAsync​(String doc)
        Attach doc to message
        Parameters:
        doc - Doc link: url, from disk or already uploaded to VK as doc{owner_id}_{id}
        Returns:
        this
      • sendVoiceMessage

        public void sendVoiceMessage​(String doc,
                                     Callback<Object>... callback)
        Send voice message
        Parameters:
        doc - URL or path to file
        callback - response will returns to callback
      • send

        public void send​(Callback<Object>... callback)
        Send the message
        Parameters:
        callback - will be called with response object
      • messageType

        public String messageType()
        Get the type of message
        Returns:
        type of message
      • hasFwds

        public boolean hasFwds()
        Returns:
        true if message has forwarded messages
      • getForwardedMessages

        public org.json.JSONArray getForwardedMessages()
        Returns:
        array of forwarded messages or []
      • getAttachments

        public org.json.JSONArray getAttachments()
        Get attachments from message
        Returns:
        JSONArray attachments
      • isPhotoMessage

        public boolean isPhotoMessage()
      • isSimpleTextMessage

        public boolean isSimpleTextMessage()
      • isVoiceMessage

        public boolean isVoiceMessage()
      • isAudioMessage

        public boolean isAudioMessage()
      • isVideoMessage

        public boolean isVideoMessage()
      • isDocMessage

        public boolean isDocMessage()
      • isWallMessage

        public boolean isWallMessage()
      • isStickerMessage

        public boolean isStickerMessage()
      • isLinkMessage

        public boolean isLinkMessage()
      • isGifMessage

        public boolean isGifMessage()
      • getCountOfAttachmentsByType

        public Map<String,​Integer> getCountOfAttachmentsByType()
        Method helps to identify kind of message
        Returns:
        Map: key=type of attachment, value=count of attachments, key=summary - value=count of all attachments.
      • getMessageId

        public Integer getMessageId()
      • getFlags

        public Integer getFlags()
      • authorId

        public Integer authorId()
      • getTimestamp

        public Integer getTimestamp()
      • getText

        public String getText()
      • getPhotos

        public org.json.JSONArray getPhotos()
      • getChatIdLong

        public Integer getChatIdLong()
      • setChatIdLong

        public void setChatIdLong​(Integer chatIdLong)
      • getBiggestPhotoUrl

        public String getBiggestPhotoUrl​(org.json.JSONArray photos)
        Parameters:
        photos - JSONArray with photo objects
        Returns:
        URL of biggest image file
      • getVoiceMessage

        public org.json.JSONObject getVoiceMessage()
      • isMessageFromChat

        public boolean isMessageFromChat()
      • setChatId

        public void setChatId​(Integer chatId)
      • setAccessToken

        public void setAccessToken​(String accessToken)
      • getRandomId

        public Integer getRandomId()
      • getTitle

        public String getTitle()
      • setTitle

        public void setTitle​(String title)