Skip to content

Commit 55b96ee

Browse files
committed
add new project for Telegram Bot
1 parent 5c56091 commit 55b96ee

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
.sts4-cache
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/build/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/

telegram-bot-notifications-with-java/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>de.rieckpil.blog</groupId>
8+
<artifactId>telegram-bot-notifications-with-java</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.glassfish.jersey.core</groupId>
15+
<artifactId>jersey-client</artifactId>
16+
<version>2.29</version>
17+
</dependency>
18+
</dependencies>
19+
20+
<build>
21+
<finalName>${project.artifactId}</finalName>
22+
<plugins>
23+
<plugin>
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-compiler-plugin</artifactId>
26+
<version>3.8.0</version>
27+
<configuration>
28+
<release>11</release>
29+
</configuration>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>3.2.1</version>
35+
<configuration>
36+
</configuration>
37+
<executions>
38+
<execution>
39+
<phase>package</phase>
40+
<goals>
41+
<goal>shade</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-jar-plugin</artifactId>
49+
<version>3.1.1</version>
50+
<configuration>
51+
<archive>
52+
<manifest>
53+
<mainClass>de.rieckpil.blog.TelegramNotifier</mainClass>
54+
</manifest>
55+
</archive>
56+
</configuration>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
61+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package de.rieckpil.blog;
2+
3+
import javax.ws.rs.core.UriBuilder;
4+
import java.io.IOException;
5+
import java.net.http.HttpClient;
6+
import java.net.http.HttpRequest;
7+
import java.net.http.HttpResponse;
8+
import java.time.Duration;
9+
10+
public class TelegramNotifier {
11+
12+
private static final String CHAT_ID = "INSERT_HERE";
13+
private static final String TOKEN = "INSERT_HERE";
14+
15+
public static void main(String[] args) throws IOException, InterruptedException {
16+
17+
String message = "Hello World from Java 11";
18+
19+
HttpClient client = HttpClient.newBuilder()
20+
.connectTimeout(Duration.ofSeconds(5))
21+
.version(HttpClient.Version.HTTP_2)
22+
.build();
23+
24+
UriBuilder builder = UriBuilder
25+
.fromUri("https://api.telegram.org")
26+
.path("/{token}/sendMessage")
27+
.queryParam("chat_id", CHAT_ID)
28+
.queryParam("text", message);
29+
30+
HttpRequest request = HttpRequest.newBuilder()
31+
.GET()
32+
.uri(builder.build("bot" + TOKEN))
33+
.timeout(Duration.ofSeconds(5))
34+
.build();
35+
36+
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
37+
38+
System.out.println(response.statusCode());
39+
System.out.println(response.body());
40+
}
41+
}

0 commit comments

Comments
 (0)