com.github.messenger4j.receive.events.TextMessageEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of messenger4j Show documentation
Show all versions of messenger4j Show documentation
The ultimate Java library for building Chatbots on the Facebook Messenger Platform
package com.github.messenger4j.receive.events;
import static com.github.messenger4j.internal.JsonHelper.Constants.PROP_ID;
import static com.github.messenger4j.internal.JsonHelper.Constants.PROP_MESSAGE;
import static com.github.messenger4j.internal.JsonHelper.Constants.PROP_MID;
import static com.github.messenger4j.internal.JsonHelper.Constants.PROP_RECIPIENT;
import static com.github.messenger4j.internal.JsonHelper.Constants.PROP_SENDER;
import static com.github.messenger4j.internal.JsonHelper.Constants.PROP_TEXT;
import static com.github.messenger4j.internal.JsonHelper.Constants.PROP_TIMESTAMP;
import static com.github.messenger4j.internal.JsonHelper.getPropertyAsDate;
import static com.github.messenger4j.internal.JsonHelper.getPropertyAsString;
import com.google.gson.JsonObject;
import java.util.Date;
/**
* This event will occur when a {@code text message} has been sent to your page.
*
*
* For further information refer to:
*
* https://developers.facebook.com/docs/messenger-platform/webhook-reference/message
*
*
*
* @author Max Grabenhorst
* @since 0.6.0
* @see Event
*/
public final class TextMessageEvent extends CommonTextMessageEvent {
/**
* Internal method to create an instance of {@link TextMessageEvent} from the given
* event as JSON structure.
*
* @param jsonObject the event as JSON structure
* @return the created {@link TextMessageEvent}
*/
public static TextMessageEvent fromJson(JsonObject jsonObject) {
final String senderId = getPropertyAsString(jsonObject, PROP_SENDER, PROP_ID);
final String recipientId = getPropertyAsString(jsonObject, PROP_RECIPIENT, PROP_ID);
final Date timestamp = getPropertyAsDate(jsonObject, PROP_TIMESTAMP);
final String mid = getPropertyAsString(jsonObject, PROP_MESSAGE, PROP_MID);
final String text = getPropertyAsString(jsonObject, PROP_MESSAGE, PROP_TEXT);
return new TextMessageEvent(senderId, recipientId, timestamp, mid, text);
}
public TextMessageEvent(String senderId, String recipientId, Date timestamp, String mid, String text) {
super(senderId, recipientId, timestamp, mid, text);
}
@Override
public boolean equals(Object o) {
return super.equals(o);
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public String toString() {
return "TextMessageEvent{} super=" + super.toString();
}
}