TDLightTelegramBots/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java

133 lines
4.0 KiB
Java
Raw Normal View History

2016-01-14 23:09:19 +01:00
package org.telegram.telegrambots.api.methods;
2016-01-14 01:14:53 +01:00
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
2016-02-27 03:17:06 +01:00
2016-01-14 01:14:53 +01:00
import org.json.JSONObject;
2016-04-12 19:53:21 +02:00
import org.telegram.telegrambots.Constants;
2016-01-14 23:09:19 +01:00
import org.telegram.telegrambots.api.objects.Message;
2016-01-14 01:14:53 +01:00
import java.io.IOException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to send text messages. On success, the sent Message is returned.
* @date 20 of June of 2015
*/
public class ForwardMessage extends BotApiMethod<Message> {
public static final String PATH = "forwardmessage";
public static final String CHATID_FIELD = "chat_id";
public static final String FROMCHATID_FIELD = "from_chat_id";
public static final String MESSAGEID_FIELD = "message_id";
2016-02-27 03:17:06 +01:00
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
2016-04-12 19:53:21 +02:00
private String chatId; ///< Unique identifier for the chat to send the message to (or username for channels)
private Integer fromChatId; ///< Unique identifier for the chat where the original message was sent — User or GroupChat id
private Integer messageId; ///< Unique message identifier
2016-02-27 03:17:06 +01:00
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
2016-01-14 01:14:53 +01:00
public ForwardMessage() {
super();
}
public String getChatId() {
return chatId;
}
public ForwardMessage setChatId(String chatId) {
2016-01-14 01:14:53 +01:00
this.chatId = chatId;
return this;
2016-01-14 01:14:53 +01:00
}
public Integer getFromChatId() {
return fromChatId;
}
public ForwardMessage setFromChatId(Integer fromChatId) {
2016-01-14 01:14:53 +01:00
this.fromChatId = fromChatId;
return this;
2016-01-14 01:14:53 +01:00
}
public Integer getMessageId() {
return messageId;
}
public ForwardMessage setMessageId(Integer messageId) {
2016-01-14 01:14:53 +01:00
this.messageId = messageId;
return this;
2016-01-14 01:14:53 +01:00
}
2016-02-27 03:17:06 +01:00
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
2016-01-14 01:14:53 +01:00
@Override
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
gen.writeStringField(METHOD_FIELD, PATH);
gen.writeStringField(CHATID_FIELD, chatId);
gen.writeNumberField(FROMCHATID_FIELD, fromChatId);
gen.writeNumberField(MESSAGEID_FIELD, messageId);
2016-02-27 03:17:06 +01:00
if (disableNotification != null) {
gen.writeBooleanField(DISABLENOTIFICATION_FIELD, disableNotification);
}
2016-01-14 01:14:53 +01:00
gen.writeEndObject();
gen.flush();
}
@Override
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
serialize(gen, serializers);
}
@Override
public JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
jsonObject.put(CHATID_FIELD, chatId);
jsonObject.put(FROMCHATID_FIELD, fromChatId);
jsonObject.put(MESSAGEID_FIELD, messageId);
2016-02-27 03:17:06 +01:00
if (disableNotification != null) {
jsonObject.put(DISABLENOTIFICATION_FIELD, disableNotification);
}
2016-01-14 01:14:53 +01:00
return jsonObject;
}
@Override
public String getPath() {
return PATH;
}
@Override
public Message deserializeResponse(JSONObject answer) {
2016-04-12 19:53:21 +02:00
if (answer.getBoolean(Constants.RESPONSEFIELDOK)) {
return new Message(answer.getJSONObject(Constants.RESPONSEFIELDRESULT));
2016-01-14 01:14:53 +01:00
}
return null;
}
@Override
public String toString() {
return "ForwardMessage{" +
"chatId='" + chatId + '\'' +
", fromChatId=" + fromChatId +
", messageId=" + messageId +
'}';
}
2016-01-14 01:14:53 +01:00
}