TelegramBots/telegrambots-spring-boot-starter
Roman_Meerson 01e046632c Added FAQ
2018-04-19 15:51:30 +04:00
..
src/main/java/org/telegram/telegrambots/starter Added spring boot starter module 2018-04-17 14:01:48 +04:00
pom.xml Added spring boot starter module 2018-04-17 14:01:48 +04:00
README.md Added FAQ 2018-04-19 15:51:30 +04:00

abilitybots

Build Status Jitpack JavaDoc Telegram ghit.me

Usage

Maven

    <dependency>
        <groupId>org.telegram</groupId>
        <artifactId>telegrambots-spring-boot-starter</artifactId>
        <version>3.6</version>
    </dependency>

Gradle

    compile "org.telegram:telegrambots-spring-boot-starter:3.6"

Motivation

If you are spring boot user it`s better to be in touch with spring starters. This module allows to register bots in spring context automatically and also use them as standard spring beans.

How to use

Your main spring boot class should look like this:

@SpringBootApplication
//Add this annotation to enable automatic bots initializing
@EnableTelegramBots
public class YourApplicationMainClass {

	public static void main(String[] args) {
	    //Add this line to initialize bots context
		ApiContextInitializer.init();
		
		SpringApplication.run(MusicUploaderApplication.class, args);
	}
}

After that your bot will look like:

  //Standart Spring component annotation
  @Component
  public class YourBotName extends TelegramLongPollingBot {
    //Bot body.
  }

Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api.