Skip to content

Commit

Permalink
Merge pull request rubenlagus#94 from rubenlagus/dev
Browse files Browse the repository at this point in the history
v2.3.3.3
  • Loading branch information
rubenlagus committed Jun 9, 2016
2 parents 946b543 + 4fc3cc3 commit 0b114ae
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 69 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Both ways are supported, but I recommend long polling method.

## Usage

Just import add the library to your project using [Maven, Gradly, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.3.2) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.3.2)
Just import add the library to your project using [Maven, Gradly, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.3.3) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.3.3)

In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

If you like to use Webhook, extend `org.telegram.telegrambots.bots.TelegramWebhookBot`


Once done, you just need to creat a `org.telegram.telegrambots.TelegramBotsApi`and register your bots:
Once done, you just need to create a `org.telegram.telegrambots.TelegramBotsApi`and register your bots:

```java

Expand Down Expand Up @@ -59,6 +59,8 @@ https://telegram.me/TGlanguagesbot (**Send files uploding them**)

https://telegram.me/RaeBot (**Inline support**)

https://telegram.me/SnowcrashBot (**Webhook support**)

You can see code for those bots at [TelegramBotsExample](https://github.com/rubenlagus/TelegramBotsExample) project.

## Telegram Bot API
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<packaging>jar</packaging>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>2.3.3.2</version>
<version>2.3.3.3</version>

<name>Telegram Bots</name>
<url>https://telegram.me/JavaBotsApi</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
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";
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String CHATID_FIELD = "chat_id";
private static final String FROMCHATID_FIELD = "from_chat_id";
private static final String MESSAGEID_FIELD = "message_id";
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
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 String fromChatId; ///< Unique identifier for the chat where the original message was sent — User or GroupChat id
private Integer messageId; ///< Unique message identifier
/**
* Optional. Sends the message silently.
Expand All @@ -47,11 +47,17 @@ public ForwardMessage setChatId(String chatId) {
return this;
}

public Integer getFromChatId() {
@Deprecated
public ForwardMessage setFromChatId(Integer fromChatId) {
this.fromChatId = fromChatId.toString();
return this;
}

public String getFromChatId() {
return fromChatId;
}

public ForwardMessage setFromChatId(Integer fromChatId) {
public ForwardMessage setFromChatId(String fromChatId) {
this.fromChatId = fromChatId;
return this;
}
Expand Down Expand Up @@ -82,7 +88,7 @@ public void serialize(JsonGenerator gen, SerializerProvider serializers) throws
gen.writeStartObject();
gen.writeStringField(METHOD_FIELD, PATH);
gen.writeStringField(CHATID_FIELD, chatId);
gen.writeNumberField(FROMCHATID_FIELD, fromChatId);
gen.writeStringField(FROMCHATID_FIELD, fromChatId);
gen.writeNumberField(MESSAGEID_FIELD, messageId);
if (disableNotification != null) {
gen.writeBooleanField(DISABLENOTIFICATION_FIELD, disableNotification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;

import java.io.File;
import java.io.InputStream;

/**
* @author Ruben Bermudez
* @version 1.0
Expand Down Expand Up @@ -36,8 +39,11 @@ public class SendAudio {
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private String performer; ///< Optional. Performer of sent audio
private String title; ///< Optional. Title of sent audio
private boolean isNewAudio;

private boolean isNewAudio; ///< True to upload a new audio, false to use a fileId
private String audioName;
private File newAudioFile; ///< New audio file
private InputStream newAudioStream; ///< New audio stream

public SendAudio() {
super();
Expand Down Expand Up @@ -82,14 +88,35 @@ public SendAudio setAudio(String audio) {
*
* @param audio Path to the new file in your server
* @param audioName Name of the file itself
*
* @deprecated use {@link #setNewAudio(File)} or {@link #setNewAudio(InputStream)} instead.
*/
@Deprecated
public SendAudio setNewAudio(String audio, String audioName) {
this.audio = audio;
this.isNewAudio = true;
this.audioName = audioName;
return this;
}

/**
* Use this method to set the audio to a new file
*
* @param file New audio file
*/
public SendAudio setNewAudio(File file) {
this.audio = file.getName();
this.isNewAudio = true;
this.newAudioFile = file;
return this;
}

public SendAudio setNewAudio(InputStream inputStream) {
this.isNewAudio = true;
this.newAudioStream = inputStream;
return this;
}

public Integer getReplayToMessageId() {
return replayToMessageId;
}
Expand Down Expand Up @@ -148,6 +175,14 @@ public String getAudioName() {
return audioName;
}

public File getNewAudioFile() {
return newAudioFile;
}

public InputStream getNewAudioStream() {
return newAudioStream;
}

@Override
public String toString() {
return "SendAudio{" +
Expand All @@ -158,7 +193,6 @@ public String toString() {
", performer='" + performer + '\'' +
", title='" + title + '\'' +
", isNewAudio=" + isNewAudio +
", audioName='" + audioName + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;

import java.io.File;
import java.io.InputStream;

/**
* @author Ruben Bermudez
* @version 1.0
Expand All @@ -28,8 +31,10 @@ public class SendDocument {
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard

private boolean isNewDocument;
private boolean isNewDocument; ///< True to upload a new document, false to use a fileId
private String documentName;
private File newDocumentFile; ///< New document file
private InputStream newDocumentStream; ///< New document stream

public SendDocument() {
super();
Expand All @@ -48,19 +53,57 @@ public String getDocument() {
return document;
}

/**
* Use this method to set the document to an document existing in Telegram system
*
* @param document File_id of the document to send
* @note The file_id must have already been received or sent by your bot
*/
public SendDocument setDocument(String document) {
this.document = document;
this.isNewDocument = false;
return this;
}

/**
* Use this method to set the document to a new file
*
* @param document Path to the new file in your server
* @param documentName Name of the file itself
*
* @deprecated use {@link #setNewDocument(File)} or {@link #setNewDocument(InputStream)} instead.
*/
@Deprecated
public SendDocument setNewDocument(String document, String documentName) {
this.document = document;
this.isNewDocument = true;
this.documentName = documentName;
return this;
}

/**
* Use this method to set the document to a new file
*
* @param file New document file
*/
public SendDocument setNewDocument(File file) {
this.document = file.getName();
this.isNewDocument = true;
this.newDocumentFile = file;
return this;
}

/**
* Use this method to set the document to a new file
*
* @param inputStream New document file
*/
public SendDocument setNewDocument(InputStream inputStream) {
this.isNewDocument = true;
this.newDocumentStream = inputStream;
return this;
}

public boolean isNewDocument() {
return isNewDocument;
}
Expand All @@ -69,6 +112,14 @@ public String getDocumentName() {
return documentName;
}

public File getNewDocumentFile() {
return newDocumentFile;
}

public InputStream getNewDocumentStream() {
return newDocumentStream;
}

public Integer getReplayToMessageId() {
return replayToMessageId;
}
Expand Down Expand Up @@ -118,7 +169,6 @@ public String toString() {
", replayToMessageId=" + replayToMessageId +
", replayMarkup=" + replayMarkup +
", isNewDocument=" + isNewDocument +
", documentName='" + documentName + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;

import java.io.File;
import java.io.InputStream;

/**
* @author Ruben Bermudez
* @version 1.0
Expand Down Expand Up @@ -30,7 +33,8 @@ public class SendPhoto {

private boolean isNewPhoto; ///< True if the photo must be uploaded from a file, file if it is a fileId
private String photoName; ///< Name of the photo

private File newPhotoFile; // New photo file
private InputStream newPhotoStream; // New photo stream

public SendPhoto() {
super();
Expand Down Expand Up @@ -90,6 +94,14 @@ public String getPhotoName() {
return photoName;
}

public File getNewPhotoFile() {
return newPhotoFile;
}

public InputStream getNewPhotoStream() {
return newPhotoStream;
}

public Boolean getDisableNotification() {
return disableNotification;
}
Expand All @@ -104,13 +116,35 @@ public SendPhoto disableNotification() {
return this;
}

/**
* Use this method to set the photo to a new file
*
* @param photo Path to the new file in your server
* @param photoName Name of the file itself
*
* @deprecated use {@link #setNewPhoto(File)} or {@link #setNewPhoto(InputStream)} instead.
*/
@Deprecated
public SendPhoto setNewPhoto(String photo, String photoName) {
this.photo = photo;
this.isNewPhoto = true;
this.photoName = photoName;
return this;
}

public SendPhoto setNewPhoto(File file) {
this.photo = file.getName();
this.newPhotoFile = file;
this.isNewPhoto = true;
return this;
}

public SendPhoto setNewPhoto(InputStream inputStream) {
this.newPhotoStream = inputStream;
this.isNewPhoto = true;
return this;
}

@Override
public String toString() {
return "SendPhoto{" +
Expand All @@ -120,7 +154,6 @@ public String toString() {
", replayToMessageId=" + replayToMessageId +
", replayMarkup=" + replayMarkup +
", isNewPhoto=" + isNewPhoto +
", photoName='" + photoName + '\'' +
'}';
}
}
Loading

0 comments on commit 0b114ae

Please sign in to comment.