Merge pull request #253 from rubenlagus/dev

Version 3.0.2
This commit is contained in:
Ruben Bermudez 2017-06-18 15:17:28 +02:00 committed by GitHub
commit 383b48cddd
32 changed files with 642 additions and 58 deletions

View File

@ -17,6 +17,7 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="telegrambots" />
<module name="telegrambots-extensions" />
<module name="telegrambots-meta" />
</profile>
<profile name="Annotation profile for Bots" enabled="true">
@ -29,11 +30,13 @@
<bytecodeTargetLevel>
<module name="Bots" target="1.5" />
<module name="telegrambots" target="1.8" />
<module name="telegrambots-extensions" target="1.8" />
<module name="telegrambots-meta" target="1.8" />
</bytecodeTargetLevel>
</component>
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="file://$PROJECT_DIR$/telegrambots" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/telegrambots-extensions" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/telegrambots-meta" charset="UTF-8" />
<file url="PROJECT" charset="UTF-8" />
</component>
@ -261,6 +264,7 @@
<modules>
<module fileurl="file://$PROJECT_DIR$/Bots.iml" filepath="$PROJECT_DIR$/Bots.iml" />
<module fileurl="file://$PROJECT_DIR$/telegrambots/telegrambots.iml" filepath="$PROJECT_DIR$/telegrambots/telegrambots.iml" />
<module fileurl="file://$PROJECT_DIR$/telegrambots-extensions/telegrambots-extensions.iml" filepath="$PROJECT_DIR$/telegrambots-extensions/telegrambots-extensions.iml" />
<module fileurl="file://$PROJECT_DIR$/telegrambots-meta/telegrambots-meta.iml" filepath="$PROJECT_DIR$/telegrambots-meta/telegrambots-meta.iml" />
</modules>
</component>
@ -834,6 +838,28 @@
<root url="jar://$MAVEN_REPOSITORY$/org/mockito/mockito-all/2.0.2-beta/mockito-all-2.0.2-beta-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.telegram:telegrambots-meta:3.0.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots-meta/3.0.1/telegrambots-meta-3.0.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots-meta/3.0.1/telegrambots-meta-3.0.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots-meta/3.0.1/telegrambots-meta-3.0.1-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.telegram:telegrambots:3.0.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots/3.0.1/telegrambots-3.0.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots/3.0.1/telegrambots-3.0.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots/3.0.1/telegrambots-3.0.1-sources.jar!/" />
</SOURCES>
</library>
</component>
<component name="masterDetails">
<states>

View File

@ -27,16 +27,16 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</dependency>
```
```gradle
compile "org.telegram:telegrambots:3.0.1"
compile "org.telegram:telegrambots:3.0.2"
```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.0.1)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/3.0.1)
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.0.2)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/3.0.2)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

View File

@ -58,4 +58,12 @@
### <a id="3.0.1"></a>3.0.1 ###
1. Added `getLevel` to `BotLogger` class.
2. Fix wrong URL when setting webhook
3. Bug Fixing: #244, #233
3. Bug Fixing: #244, #233
### <a id="3.0.2"></a>3.0.2 ###
1. Bug Fixing: #250
2. Added new module `telegrambots-extensions` that should contains any extensions of the API such as CommandBot or TimedBot.
3. `TelegramLongPollingCommandBot` receives now the bot username as constructor parameters, all deprecated constructors will be removed in next mayor release.
4. `getUsername` method from `TelegramLongPollingCommandBot` can be considered `final` and will be so in next mayor release.
**[[How to update to version 3.0.2|How-To-Update#3.0.2]]**

View File

@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</dependency>
```
* With **Gradle**:
```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '3.0.1'
compile group: 'org.telegram', name: 'telegrambots', version: '3.0.2'
```
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).

View File

@ -23,4 +23,8 @@
2. In `editMessageTextAsync`, `editMessageCaptionAsync` or `editMessageReplyMarkupAsync` in `AbsSender`, second parameter should become `SentCallback<Serializable>` due to new return type.
### <a id="3.0"></a>To version 3.0 ###
1. In `Message` object, field `new_chat_member` was replaced by `new_chat_members` that is now an array of users.
1. In `Message` object, field `new_chat_member` was replaced by `new_chat_members` that is now an array of users.
### <a id="3.0.2"></a>To version 3.0.2 ###
1. If you were using `TelegramLongPollingCommandBot`, add the new [extensions dependency](https://github.com/rubenlagus/TelegramBots/tree/master/telegrambots-extensions) to your maven and fix import statements in your project.
2. If you were using `TelegramLongPollingCommandBot`, make sure you start using constructors with username and prevent overriding `getUsername` method.

View File

@ -7,11 +7,12 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>3.0.1</version>
<version>3.0.2</version>
<modules>
<module>telegrambots</module>
<module>telegrambots-meta</module>
<module>telegrambots-extensions</module>
</modules>
<licenses>
@ -24,6 +25,6 @@
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<bots.version>3.0.1</bots.version>
<bots.version>3.0.2</bots.version>
</properties>
</project>

View File

@ -0,0 +1,27 @@
# Telegram Bot Extensions
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.telegram/telegrambotsextensions/badge.svg)](http://mvnrepository.com/artifact/org.telegram/telegrambotsextensions)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/rubenlagus/TelegramBots/blob/master/LICENSE)
Extensions to default bots implementation of Telegram Bots library
## Usage
Just import add the library to your project with one of these options:
1. Using Maven Central Repository:
```xml
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>3.0.2</version>
</dependency>
```
2. Using Gradle:
```gradle
compile "org.telegram:telegrambotsextensions:3.0.2"
```

View File

@ -0,0 +1,226 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>3.0.2</version>
<packaging>jar</packaging>
<name>Telegram Bots Extensions</name>
<url>https://github.com/rubenlagus/TelegramBots</url>
<description>Extensions Bots for Telegram Bots library</description>
<issueManagement>
<url>https://github.com/rubenlagus/TelegramBots/issues</url>
<system>GitHub Issues</system>
</issueManagement>
<scm>
<url>https://github.com/rubenlagus/TelegramBots</url>
<connection>scm:git:git://github.com/rubenlagus/TelegramBots.git</connection>
<developerConnection>scm:git:git@github.com:rubenlagus/TelegramBots.git</developerConnection>
</scm>
<ciManagement>
<url>https://travis-ci.org/rubenlagus/TelegramBots</url>
<system>Travis</system>
</ciManagement>
<developers>
<developer>
<email>rberlopez@gmail.com</email>
<name>Ruben Bermudez</name>
<url>https://github.com/rubenlagus</url>
<id>rubenlagus</id>
</developer>
</developers>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>3.0.2</bots.version>
</properties>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>${bots.version}</version>
</dependency>
</dependencies>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>clean-project</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<DependencyConvergence />
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -1,12 +1,15 @@
package org.telegram.telegrambots.bots;
package org.telegram.telegrambots.bots.commandbot;
import org.telegram.telegrambots.ApiContext;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.commands.BotCommand;
import org.telegram.telegrambots.bots.commands.CommandRegistry;
import org.telegram.telegrambots.bots.commands.ICommandRegistry;
import org.telegram.telegrambots.bots.AbsSender;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.bots.commandbot.commands.CommandRegistry;
import org.telegram.telegrambots.bots.commandbot.commands.ICommandRegistry;
import java.util.Collection;
import java.util.Map;
@ -19,37 +22,82 @@ import java.util.function.BiConsumer;
*/
public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements ICommandRegistry {
private final CommandRegistry commandRegistry;
private String botUsername;
/**
* Creates a TelegramLongPollingCommandBot using default options
* Use ICommandRegistry's methods on this bot to register commands
*
* @deprecated Uses {@link #TelegramLongPollingCommandBot(String)} instead
*/
@Deprecated
public TelegramLongPollingCommandBot() {
this(ApiContext.getInstance(DefaultBotOptions.class));
}
/**
* Creates a TelegramLongPollingCommandBot using default options
* Use ICommandRegistry's methods on this bot to register commands
*
* @param botUsername Username of the bot
*/
public TelegramLongPollingCommandBot(String botUsername) {
this(ApiContext.getInstance(DefaultBotOptions.class), botUsername);
}
/**
* Creates a TelegramLongPollingCommandBot with custom options and allowing commands with
* usernames
* Use ICommandRegistry's methods on this bot to register commands
* @param options Bot options
*
* @deprecated Use {@link #TelegramLongPollingCommandBot(DefaultBotOptions, String)} instead
*/
@Deprecated
public TelegramLongPollingCommandBot(DefaultBotOptions options) {
this(options, true);
}
/**
* Creates a TelegramLongPollingCommandBot with custom options and allowing commands with
* usernames
* Use ICommandRegistry's methods on this bot to register commands
* @param options Bot options
* @param botUsername Username of the bot
*/
public TelegramLongPollingCommandBot(DefaultBotOptions options, String botUsername) {
this(options, true, botUsername);
}
/**
* Creates a TelegramLongPollingCommandBot
* Use ICommandRegistry's methods on this bot to register commands
* @param options Bot options
* @param allowCommandsWithUsername true to allow commands with parameters (default),
* false otherwise
*
* @deprecated Use {@link #TelegramLongPollingCommandBot(DefaultBotOptions, boolean, String)} instead
*/
@Deprecated
public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername) {
super(options);
this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, getBotUsername());
}
/**
* Creates a TelegramLongPollingCommandBot
* Use ICommandRegistry's methods on this bot to register commands
* @param options Bot options
* @param allowCommandsWithUsername true to allow commands with parameters (default),
* false otherwise
* @param botUsername bot username of this bot
*/
public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername, String botUsername) {
super(options);
this.botUsername = botUsername;
this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, botUsername);
}
@Override
public final void onUpdateReceived(Update update) {
if (update.hasMessage()) {
@ -115,6 +163,15 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
return commandRegistry.getRegisteredCommand(commandIdentifier);
}
/**
* TODO This method will become final in next mayor release, avoid overriding it
* @return Bot username
*/
@Override
public String getBotUsername() {
return botUsername;
}
/**
* Process all updates, that are not commands.
* @warning Commands that have valid syntax but are not registered on this bot,

View File

@ -1,4 +1,4 @@
package org.telegram.telegrambots.bots.commands;
package org.telegram.telegrambots.bots.commandbot.commands;
import org.telegram.telegrambots.api.objects.Chat;
import org.telegram.telegrambots.api.objects.User;

View File

@ -1,4 +1,4 @@
package org.telegram.telegrambots.bots.commands;
package org.telegram.telegrambots.bots.commandbot.commands;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.bots.AbsSender;

View File

@ -1,4 +1,4 @@
package org.telegram.telegrambots.bots.commands;
package org.telegram.telegrambots.bots.commandbot.commands;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.bots.AbsSender;

View File

@ -0,0 +1,218 @@
package org.telegram.telegrambots.bots.timedbot;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Created by Daniil Nikanov aka JetCoder
*/
public abstract class TimedSendLongPollingBot extends TelegramLongPollingBot
{
private static final long MANY_CHATS_SEND_INTERVAL = 33;
private static final long ONE_CHAT_SEND_INTERVAL = 1000;
private static final long CHAT_INACTIVE_INTERVAL = 1000 * 60 * 10;
private final Timer mSendTimer = new Timer(true);
private final ConcurrentHashMap<Long,MessageQueue> mMessagesMap = new ConcurrentHashMap<>(32, 0.75f, 1);
private final ArrayList<MessageQueue> mSendQueues = new ArrayList<>();
private final AtomicBoolean mSendRequested = new AtomicBoolean(false);
private final class MessageSenderTask extends TimerTask
{
@Override
public void run()
{
//mSendRequested used for optimisation to not traverse all mMessagesMap 30 times per second all the time
if (!mSendRequested.getAndSet(false))
return;
long currentTime = System.currentTimeMillis();
mSendQueues.clear();
boolean processNext = false;
//First step - find all chats in which already allowed to send message (passed more than 1000 ms from previuos send)
Iterator<Map.Entry<Long,MessageQueue>> it = mMessagesMap.entrySet().iterator();
while (it.hasNext())
{
MessageQueue queue = it.next().getValue();
int state = queue.getCurrentState(currentTime); //Actual check here
if (state == MessageQueue.GET_MESSAGE)
{
mSendQueues.add(queue);
processNext = true;
}
else if (state == MessageQueue.WAIT)
{
processNext = true;
}
else if (state == MessageQueue.DELETE)
{
it.remove();
}
}
//If any of chats are in state WAIT or GET_MESSAGE, request another iteration
if (processNext)
mSendRequested.set(true);
//Second step - find oldest waiting queue and peek it's message
MessageQueue sendQueue = null;
long oldestPutTime = Long.MAX_VALUE;
for (int i = 0; i < mSendQueues.size(); i++)
{
MessageQueue queue = mSendQueues.get(i);
long putTime = queue.getPutTime();
if (putTime < oldestPutTime)
{
oldestPutTime = putTime;
sendQueue = queue;
}
}
if (sendQueue == null) //Possible if on first step wasn't found any chats in state GET_MESSAGE
return;
//Invoke the send callback. ChatId is passed for possible additional processing
sendMessageCallback(sendQueue.getChatId(), sendQueue.getMessage(currentTime));
}
}
private static class MessageQueue
{
public static final int EMPTY = 0; //Queue is empty
public static final int WAIT = 1; //Queue has message(s) but not yet allowed to send
public static final int DELETE = 2; //No one message of given queue was sent longer than CHAT_INACTIVE_INTERVAL, delete for optimisation
public static final int GET_MESSAGE = 3; //Queue has message(s) and ready to send
private final ConcurrentLinkedQueue<Object> mQueue = new ConcurrentLinkedQueue<>();
private final Long mChatId;
private long mLastSendTime; //Time of last peek from queue
private volatile long mLastPutTime; //Time of last put into queue
public MessageQueue(Long chatId)
{
mChatId = chatId;
}
public synchronized void putMessage(Object msg)
{
mQueue.add(msg);
mLastPutTime = System.currentTimeMillis();
}
public synchronized int getCurrentState(long currentTime)
{
//currentTime is passed as parameter for optimisation to do not recall currentTimeMillis() many times
long interval = currentTime - mLastSendTime;
boolean empty = mQueue.isEmpty();
if (!empty && interval > ONE_CHAT_SEND_INTERVAL)
return GET_MESSAGE;
else if (interval > CHAT_INACTIVE_INTERVAL)
return DELETE;
else if (empty)
return EMPTY;
else
return WAIT;
}
public synchronized Object getMessage(long currentTime)
{
mLastSendTime = currentTime;
return mQueue.poll();
}
public long getPutTime()
{
return mLastPutTime;
}
public Long getChatId()
{
return mChatId;
}
}
//Constructor
protected TimedSendLongPollingBot()
{
mSendTimer.schedule(new MessageSenderTask(), MANY_CHATS_SEND_INTERVAL, MANY_CHATS_SEND_INTERVAL);
}
//Something like destructor
public void finish()
{
mSendTimer.cancel();
}
//This method must be called instead of all calls to sendMessage(), editMessageText(), sendChatAction() etc...
//for performing time-based sends obeying the basic Telegram limits (no more 30 msgs per second in different chats,
//no more 1 msg per second in any single chat). The method can be safely called from multiple threads.
//Order of sends to any given chat is guaranteed to remain the same as order of calls. Sends to different chats can be out-of-order depending on timing.
//Example of call:
/**
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(chatId);
sendMessageRequest.setParseMode("HTML");
sendMessageRequest.setText(text);
sendMessageRequest.setReplyMarkup(replyMarkup);
sendTimed(chatId, sendMessageRequest); // <-- Instead of sendMessage() API method
*/
public void sendTimed(Long chatId, Object messageRequest)
{
MessageQueue queue = mMessagesMap.get(chatId);
if (queue == null)
{
queue = new MessageQueue(chatId);
queue.putMessage(messageRequest);
mMessagesMap.put(chatId, queue);
}
else
{
queue.putMessage(messageRequest);
mMessagesMap.putIfAbsent(chatId, queue); //Double check, because the queue can be removed from hashmap on state DELETE
}
mSendRequested.set(true);
}
//When time of actual send comes this callback is called with the same parameters as in call to sendTimed().
//It's implementation must use 'instanceof' operator to distinguish type of the message request and call the proper send API method.
//Example:
/**
//@Override
public void sendMessageCallback(Long chatId, Object messageRequest)
{
try
{
if (messageRequest instanceof SendMessage)
{
sendMessage((SendMessage) messageRequest);
}
else if (messageRequest instanceof EditMessageText)
{
editMessageText((EditMessageText) messageRequest);
}
else if (messageRequest instanceof SendChatAction)
{
sendChatAction((SendChatAction) messageRequest);
}
else if (messageRequest instanceof SendDocument)
{
sendDocument((SendDocument) messageRequest);
}
//Etc...
}
catch (TelegramApiException e)
{
LOG.error(EXC, e);
}
catch (Exception e)
{
LOG.fatal(EXC, e);
}
}
*/
public abstract void sendMessageCallback(Long chatId, Object messageRequest);
}

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<packaging>jar</packaging>
<name>Telegram Bots Meta</name>

View File

@ -14,8 +14,7 @@ import java.util.Objects;
/**
* @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
* Use this method to send text messages. On success, the sent Message is returned.
*/
public class ForwardMessage extends BotApiMethod<Message> {
public static final String PATH = "forwardmessage";
@ -44,6 +43,42 @@ public class ForwardMessage extends BotApiMethod<Message> {
super();
}
public ForwardMessage(String chatId, String fromChatId, Integer messageId) {
this();
Objects.requireNonNull(chatId);
Objects.requireNonNull(fromChatId);
this.chatId = chatId;
this.fromChatId = fromChatId;
this.messageId = messageId;
}
public ForwardMessage(String chatId, Long fromChatId, Integer messageId) {
this();
Objects.requireNonNull(chatId);
Objects.requireNonNull(fromChatId);
this.chatId = chatId;
this.fromChatId = fromChatId.toString();
this.messageId = messageId;
}
public ForwardMessage(Long chatId, String fromChatId, Integer messageId) {
this();
Objects.requireNonNull(chatId);
Objects.requireNonNull(fromChatId);
this.chatId = chatId.toString();
this.fromChatId = fromChatId;
this.messageId = messageId;
}
public ForwardMessage(Long chatId, Long fromChatId, Integer messageId) {
this();
Objects.requireNonNull(chatId);
Objects.requireNonNull(fromChatId);
this.chatId = chatId.toString();
this.fromChatId = fromChatId.toString();
this.messageId = messageId;
}
public String getChatId() {
return chatId;
}
@ -68,6 +103,12 @@ public class ForwardMessage extends BotApiMethod<Message> {
return this;
}
public ForwardMessage setFromChatId(Long fromChatId) {
Objects.requireNonNull(fromChatId);
this.fromChatId = fromChatId.toString();
return this;
}
public Integer getMessageId() {
return messageId;
}
@ -93,10 +134,10 @@ public class ForwardMessage extends BotApiMethod<Message> {
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null) {
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (fromChatId == null) {
if (fromChatId == null || fromChatId.isEmpty()) {
throw new TelegramApiValidationException("FromChatId can't be empty", this);
}
if (messageId == null) {
@ -128,8 +169,9 @@ public class ForwardMessage extends BotApiMethod<Message> {
public String toString() {
return "ForwardMessage{" +
"chatId='" + chatId + '\'' +
", fromChatId=" + fromChatId +
", fromChatId='" + fromChatId + '\'' +
", messageId=" + messageId +
", disableNotification=" + disableNotification +
'}';
}
}

View File

@ -11,8 +11,7 @@ import java.io.Serializable;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 06 of November of 2016
* Response from Telegram Server
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)

View File

@ -3,8 +3,7 @@ package org.telegram.telegrambots.generics;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
* Bot options
*/
public interface BotOptions {
String getBaseUrl();

View File

@ -3,8 +3,7 @@ package org.telegram.telegrambots.generics;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
* Bot session interface
*/
public interface BotSession {
void setOptions(BotOptions options);

View File

@ -3,8 +3,7 @@ package org.telegram.telegrambots.generics;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
* Base Updates Handler interface
*/
public interface UpdatesHandler {
}

View File

@ -3,8 +3,7 @@ package org.telegram.telegrambots.generics;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
* Updates reader interface
*/
public interface UpdatesReader {
void start();

View File

@ -5,8 +5,7 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
* Webhook interface
*/
public interface Webhook {
void startServer() throws TelegramApiRequestException;

View File

@ -3,8 +3,6 @@ package org.telegram.telegrambots.test;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 04 of November of 2016
*/
public final class TelegramBotsHelper {
private TelegramBotsHelper() {

View File

@ -27,8 +27,6 @@ import java.util.List;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 04 of November of 2016
*/
public class TestDeserialization {
private ObjectMapper mapper;

View File

@ -9,8 +9,6 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
*/
public class TestTelegramApi extends TestBase {

View File

@ -3,8 +3,6 @@ package org.telegram.telegrambots.test.asserts;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 04 of November of 2016
*/
public final class ApiAssert {
private ApiAssert() {}

View File

@ -10,8 +10,6 @@ import org.telegram.telegrambots.generics.Webhook;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
*/
public abstract class TestBase {

View File

@ -7,8 +7,6 @@ import org.telegram.telegrambots.generics.LongPollingBot;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
*/
public class FakeBotSession implements BotSession {
@Override

View File

@ -7,8 +7,6 @@ import org.telegram.telegrambots.generics.WebhookBot;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
*/
public class FakeWebhook implements Webhook {
private String internalUrl;

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<packaging>jar</packaging>
<name>Telegram Bots</name>
@ -66,7 +66,7 @@
<jackson.version>2.8.7</jackson.version>
<jacksonanotation.version>2.8.0</jacksonanotation.version>
<commonio.version>2.5</commonio.version>
<bots.version>3.0.1</bots.version>
<bots.version>3.0.2</bots.version>
</properties>
<dependencyManagement>

View File

@ -8,8 +8,7 @@ import org.telegram.telegrambots.updatesreceivers.DefaultWebhook;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 29 of October of 2016
* Initialization of ApiContext
*/
public final class ApiContextInitializer {
private ApiContextInitializer() {

View File

@ -43,8 +43,6 @@ import java.util.List;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 02 of November of 2016
*/
public final class BotApiMethodHelperFactory {
private BotApiMethodHelperFactory() {
@ -102,7 +100,7 @@ public final class BotApiMethodHelperFactory {
}
public static BotApiMethod getForwardMessage() {
return new ForwardMessage()
return new ForwardMessage(54L, 123L, 55)
.setFromChatId("From")
.setChatId("To")
.setMessageId(15)

View File

@ -31,8 +31,6 @@ import static org.junit.Assert.fail;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief TODO
* @date 01 of November of 2016
*/
public class TestRestApi extends JerseyTest {