xabgesagtx / telegram-spring-boot-starter

Telegram Bot API Spring Boot Starter
MIT License
127 stars 41 forks source link
spring spring-boot spring-boot-starter telegram telegram-bot telegram-bot-api

**This project is archived. Please use the spring boot starter of the TelegramBots java library instead!***

Telegram Spring Boot Starter

build badge Maven Central Jitpack

This is a starter pom for a spring boot application with the TelegramBots Java API.

The starter is available at maven central. Just add the following dependency to your pom:

<dependency>
    <groupId>com.github.xabgesagtx</groupId>
    <artifactId>telegram-spring-boot-starter</artifactId>
    <version>0.26</version>
</dependency>

For gradle users just add this to your dependencies:

compile('com.github.xabgesagtx:telegram-spring-boot-starter:0.26')

The only thing you need to do after adding the dependency is to create a bean for a bot. E.g.:

@Component
public class Bot extends TelegramLongPollingBot {
...
} 

or for a webhook bot:

@Component
public class Bot extends TelegramWebhookBot {
... 
}

if you want to overwrite a webhook for a specific bot:

@Component
public class Bot extends CustomizableTelegramWebhookBot {
... 
}

The bot will then be registered for you automatically on startup.

Configuration

The following properties can be configured (none are mandatory):

property description available since
telegram.external-url external base url for the webhook 0.15
telegram.internal-url internal base url for the webhook 0.15
telegram.key-store keystore for the server 0.15
telegram.key-store-password keystore password for the server 0.15
telegram.path-to-certificate full path for .pem public certificate keys 0.15
telegram.proxy.type type of proxy (NO_PROXY, HTTP, SOCKS4, SOCKS5) 0.22
telegram.proxy.host host of the proxy 0.22
telegram.proxy.port port of the proxy 0.22
telegram.proxy.user username for proxy authentication 0.22
telegram.proxy.password password for proxy authentication 0.22

Webhook support

You need to configure at least telegram.external-url and telegram.internal-url for webhook support. This configuration leaves the HTTPS handling to a proxy.

If you configure telegram.key-store for your HTTPS webhook bot, you need to configure telegram.key-store-password as well.

Also, telegram.path-to-certificate will only be used, if you configure the keystore.

Proxy support

For proxy support you need to set all of the following properties:

To enable authentication for a proxy you need to set telegram.proxy.user and telegram.proxy.password.

General

In a regular spring boot setting these properties can be set in your application.properties or application.yml.

For more information on how these configuration options work, please refer to the TelegramBots Java API.

Example

An implementation example is available too.