Skip to content

Commit

Permalink
0.0.1 release
Browse files Browse the repository at this point in the history
Create new actions by implementing the TelegramActionHandler class and
register them to your TeleBot object.
  • Loading branch information
EXH3Y committed Dec 5, 2015
1 parent 2dd7aee commit 52950a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
11 changes: 8 additions & 3 deletions telebot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

<groupId>exh3y</groupId>
<artifactId>telebot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<packaging>jar</packaging>

<name>telebot</name>
<url>http://maven.apache.org</url>
<name>TeleBot</name>
<url>https://github.com/EXH3Y/TeleBot</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -29,4 +29,9 @@
<version>1.4.7</version>
</dependency>
</dependencies>
<description>A simple library to create telegram bots.</description>
<issueManagement>
<url>https://github.com/EXH3Y/TeleBot/issues</url>
<system>GitHub Issues</system>
</issueManagement>
</project>
22 changes: 19 additions & 3 deletions telebot/src/main/java/exh3y/telebot/TeleBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ public class TeleBot extends Thread {

private final String endpoint;
private final String token;

private long pollingIntervall = 1000;

private HashMap<String, TelegramActionHandler> actionConnector;
private TelegramActionHandler defaultAction = null;
private TelegramActionHandler defaultAction = null;

/**
* <p>
Expand Down Expand Up @@ -132,6 +135,19 @@ public HttpResponse<JsonNode> getUpdates(Integer offset) throws UnirestException
return Unirest.post(endpoint + token + "/getUpdates").field("offset", offset).asJson();
}

/**
* <p>
* Sets the time to wait between update requests.
* </p>
*
* @param millis
* Milliseconds to wait.
*/
public void setPollingIntervall(long millis) {

this.pollingIntervall = millis;
}

@Override
public void run() {

Expand All @@ -155,7 +171,7 @@ public void run() {

for (int i = 0; i < jsonResponse.length(); i++) {

// Iterate through messages in the last update
// Iterate over the messages in the last update
JSONObject message = jsonResponse.getJSONObject(i).getJSONObject("message");

if (message.has("text")) {
Expand All @@ -176,7 +192,7 @@ public void run() {
} catch (UnirestException e) {

try {
sleep(1000);
sleep(this.pollingIntervall);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
Expand Down

0 comments on commit 52950a6

Please sign in to comment.