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

com.github.messenger4j.receive.events.TextMessageEvent Maven / Gradle / Ivy

Go to download

The ultimate Java library for building Chatbots on the Facebook Messenger Platform

There is a newer version: 1.1.0
Show newest version
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(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy