Week 8: Java
In this chapter, we are going to tackle a Telegram bot in Java. The API in Java is not as bad as it looks, and debugging Java code in Visual Studio Code also works slightly better than expected.
- PDF / 958,549 Bytes
- 21 Pages / 439.37 x 666.142 pts Page_size
- 51 Downloads / 210 Views
Week 8: Java Coffee is a language in itself. —Jackie Chan In this chapter, we are going to tackle a Telegram bot in Java. The API in Java is not as bad as it looks, and debugging Java code in Visual Studio Code also works slightly better than expected. The project will use the Java de facto build tool, Gradle. The library will be the java-telegram-bot-api. Telegram is now proposing a payment API, so you can start selling stuff directly through Telegram. This is especially effective for selling services. While the first part of this chapter will revisit the basics, we will then implement a bot that responds to the challenges of using the Telegram Payment API and create an example of the full payment life cycle.
Installation Apart from Apache Maven, Gradle is the de facto build tool in Java land. It’s actually the main build tool for building Android applications. You can manually download and install Gradle on your machine, by downloading binaries available through the different package managers. The Gradle web site (https://gradle.org/install/) has an extensive section on how to install the software.
© Nicolas Modrzyk 2019 N. Modrzyk, Building Telegram Bots, https://doi.org/10.1007/978-1-4842-4197-4_8
159
Chapter 8
Week 8: Java
sdkman is nice to use these days: sdk install gradle 4.10.2 Homebrew is the standard on macOS. brew install gradle Chocolatey is the standard on Windows. choco install gradle Once installed, you can check whether you have the most recent version available, which, for Gradle, at the time of writing, was version 4.10.2 $ gradle -v Welcome to Gradle 4.10.2! Here are the highlights of this release: - Incremental Java compilation by default - Periodic Gradle caches cleanup - Gradle Kotlin DSL 1.0-RC6 - Nested included builds - SNAPSHOT plugin versions in the `plugins {}` block For more details see https://docs.gradle.org/4.10.2/release- notes.html -----------------------------------------------------------Gradle 4.10.2 -----------------------------------------------------------Build time: 2018-09-19 18:10:15 UTC Revision: b4d8d5d170bb4ba516e88d7fe5647e2323d791dd Kotlin DSL: 1.0-rc-6 Kotlin: 1.2.61 160
Chapter 8
Week 8: Java
Groovy: 2.4.15 Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018 JVM: 1.8.0_171 (Oracle Corporation 25.171-b11) OS: Mac OS X 10.13.6 x86_64
The Project Structure A Java project using Gradle is mostly made of the build.gradle file, which contains metadata and build information that Gradle can understand and source files located in src/main/java (by default). . ├── build.gradle ├── resources │ ├── cat.jpg │ └── token └── src └── main └── java └── com └── hellonico ├── Invoice.java └── MyMain.java 6 directories, 5 files
The build.gradle file Gradle is quite versatile, and you can build pretty much anything with it. In our case, we are going to build a Java project, so we will use the Gradle plug-in for Java, with a
Data Loading...