Skip to content
This repository was archived by the owner on Jan 27, 2022. It is now read-only.

Commit 5141167

Browse files
committed
Updated README
1 parent ecd3675 commit 5141167

4 files changed

Lines changed: 49 additions & 19 deletions

File tree

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# TelegramBots4Java
22

3-
TelegramBots4Java is a Java implementation of the Telegram Bot API
3+
##### TelegramBots4Java is a Java implementation of the [Telegram Bot API](https://core.telegram.org/bots/api)
44

5-
See [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api)
5+
This API is designed to be *extensible*, while preserving *simplicity* and *conciseness*.
6+
It provides [core classes](https://cdn.rawgit.com/pevdh/TelegramBots4Java/master/docs/co/vandenham/telegram/botapi/requests/package-summary.html) to interact with the Telegram Bot API, and it encapsulates these classes in [one simple, extensible class](https://cdn.rawgit.com/pevdh/TelegramBots4Java/master/docs/co/vandenham/telegram/botapi/TelegramBot.html). However, nothing holds you back to use the [core classes](https://cdn.rawgit.com/pevdh/TelegramBots4Java/master/docs/co/vandenham/telegram/botapi/requests/package-summary.html) directly.
67

78
## How to obtain a Jar
89

@@ -12,12 +13,54 @@ $ git clone https://github.com/pevdh/TelegramBots4Java.git
1213
$ cd TelegramBots4Java/
1314
$ ./gradlew jar
1415
```
16+
You'll find the .jar file in the api/build/libs directory.
1517

1618
### Windows
1719
```
1820
$ git clone https://github.com/pevdh/TelegramBots4Java.git
1921
$ cd TelegramBots4Java/
2022
$ gradlew.bat jar
2123
```
24+
You'll find the .jar file in the api\build\libs directory.
2225

23-
For now, you can check out the [EchoBot example](https://github.com/pevdh/TelegramBots4Java/tree/master/EchoBot/src/main/java/co/vandenham/telegram/botapi/examples) and the [Javadocs](https://cdn.rawgit.com/pevdh/TelegramBots4Java/master/docs/index.html)
26+
## How to use
27+
28+
### A simple echo bot
29+
*The import statements are left out for simplicity.*
30+
31+
```java
32+
public class EchoBot extends TelegramBot {
33+
34+
public EchoBot() {
35+
super("<YOUR_BOT_TOKEN>");
36+
}
37+
38+
// This handler gets called whenever a user sends /start or /help
39+
@CommandHandler({"start", "help"})
40+
public void handleHelp(Message message) {
41+
replyTo(message, "Hi there! I am here to echo all your kind words back to you!");
42+
}
43+
44+
// This handler gets called whenever a user sends a general text message.
45+
@MessageHandler(contentTypes = Message.Type.TEXT)
46+
public void handleTextMessage(Message message) {
47+
System.out.println(String.format("%s: %s", message.getChat().getId(), message.getText()));
48+
replyTo(message, message.getText());
49+
}
50+
51+
// This is the default handler, called when the other two handlers don't apply.
52+
@DefaultHandler
53+
public void handleDefault(Message message) {
54+
replyTo(message, "Say what?");
55+
}
56+
57+
public static void main(String[] args) {
58+
TelegramBot bot = new EchoBot();
59+
bot.start();
60+
}
61+
}
62+
```
63+
### Further reference
64+
This project has [Javadocs](https://cdn.rawgit.com/pevdh/TelegramBots4Java/master/docs/index.html).
65+
66+
*TelegramBot.java* provides a good entry point into this API. You can have a look at the [Javadoc reference](https://cdn.rawgit.com/pevdh/TelegramBots4Java/master/docs/co/vandenham/telegram/botapi/TelegramBot.html) for this class, or look at the [source code](https://github.com/pevdh/TelegramBots4Java/blob/master/api/src/main/java/co/vandenham/telegram/botapi/TelegramBot.java) directly.

api/build.gradle

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,13 @@ test {
66
exclude 'co/vandenham/telegram/botapi/requests/*'
77
}
88

9-
task copyJar(type: Copy) {
10-
from 'build/libs'
11-
into '..'
12-
}
13-
149
task copyDocs(type: Copy) {
1510
from 'build/docs/javadoc'
1611
into '../docs'
1712
}
1813

1914
javadoc << {
20-
copyDocs.execute()
21-
}
22-
23-
jar << {
24-
copyJar.execute()
15+
copyDocs.execute()
2516
}
2617

2718
javadoc {

api/src/main/java/co/vandenham/telegram/botapi/TelegramBot.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public TelegramBot(String botToken, boolean sendAsync) {
6666
* Starts the bot.
6767
*
6868
* First, it instantiates a {@link java.util.concurrent.ExecutorService} by calling {@link TelegramBot#provideExecutorService()}.
69-
* If this bot is constructed with {@code sendAsync} set to {@code true}, it instantiates an asynchronous version
70-
* of {@link ApiRequestExecutor}. If it returns false, a synchronous version is instantiated.
69+
* If this instance is constructed with {@code sendAsync} set to {@code true}, it instantiates a asynchronous {@link ApiRequestExecutor},
70+
* otherwise a synchronous version is used.
7171
*
7272
* After this, a polling {@link java.lang.Thread} is instantiated and the bot starts polling the Telegram API.
7373
*/

build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
project.ext.set("projectName", "TelegramBots4Java")
22

3-
task getEnv {
4-
println "$System.env.TOKEN"
5-
}
6-
73
subprojects {
84

95
apply plugin: 'java'

0 commit comments

Comments
 (0)