TagFinderBot
This is a tutorial to create a telegram bot which can suggest tags/labels in an image using AWS Rekognition. We will be using TelegramBots Java API.
Steps to create the bot -
-
Create new bot and get token from https://t.me/BotFather by clicking on
/newbotcommand. Set Description, About, Botpic if you want to. -
Create a java maven project
-
Add TelegramBots API dependency.
<dependency> <groupId>org.telegram</groupId> <artifactId>telegrambots</artifactId> <version>4.1</version> </dependency>
and AWS Java SDK Rekognition dependency.
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-rekognition</artifactId>
<version>1.11.368</version>
</dependency>
Note: Make sure to use updated dependencies.
-
Create a new bot by extending
org.telegram.telegrambots.bots.TelegramLongPollingBot. Set Bot username ingetBotUsername()and Bot token ingetBotToken(). We will recieve updates inonUpdateReceived()method. -
Now create logic to get the picture sent by the user and get
ByteBufferfrom it which can be fed to AWS Rekognition to find tags. Check TagFinderBot.java for details. -
Get ACCESS_KEY and SECRET_KEY from AWS to access AWS Rekognition. Check AWSRekognition.java for code to get tags/labels from the
ByteBuffer. -
Now finally register your bot. Check TagFinderApp.java for details.
-
All done. Build the project
mvn clean install.tagfinder-0.1-jar-with-dependencies.jarwill be created in target folder. -
Start your bot 🤖 using
java -jar tagfinder-0.1-jar-with-dependencies.jar