All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viber.bot.message.TextMessage Maven / Gradle / Ivy

Go to download

Use this library to communicate with the Viber API to develop a bot for https://developers.viber.com/.

The newest version!
package com.viber.bot.message;

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

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.HashMap;
import java.util.Map;

@Immutable
public class TextMessage extends Message {

	@Nullable
    private final String text; // Text can be empty or null for inline messages

    @JsonCreator
    public TextMessage(final @JsonProperty("text") @Nullable String text,
                       final @JsonProperty("keyboard") @Nullable MessageKeyboard keyboard,
                       final @JsonProperty("tracking_data") @Nullable TrackingData trackingData,
                       final @JsonProperty("min_api_version") @Nullable Integer minApiVersion) {
        super("text", keyboard, trackingData, minApiVersion);
        this.text = text;
    }

    @JsonIgnore
    public TextMessage(final @Nullable String text) {
        this(text, null, null, null);
    }

    @Override
    protected Map getPartialMapRepresentation() {
        return new HashMap() {{
            put("text", getText());
        }};
    }

	@Nullable
    public String getText() {
        return text;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        final TextMessage that = (TextMessage) o;
        return text != null ? text.equals(that.text) : that.text == null;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (text != null ? text.hashCode() : 0);
        return result;
    }

	@Override
	public String toString() {
		return "TextMessage [text=" + text + ", messageStr=" + super.toString() + "]";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy