Telegram Bot Utilities – Java Library

Java Library: Telegram Bot Utilities 1.0

This is my simple java library that you can use to manage your Telegram’s bot, using methods similar to the ones that you can find on https://core.telegram.org/bots/.

You can download it here.

To use this library you need some external libraries, that you can find here:

Here there is a video in which I show you how to download the libraries:

After downloading these libraries, you should import in your project the following jars:

  • My jar from org.altervista.leocus.telegrambotutilities.zip
  • HttpClient, HttpCore, HttpMime, commons-loggings jars from Apache HttpClient
  • the org.json jar

You are now ok with libraries.

Here there is a video in which I show you how to import the libraries (into IntelliJ, but the procedure is similar also for other IDEs):

Now you need to create your bot with Botfather (a bot that you can find on telegram at https://telegram.me/botfather ), sending “/newbot” and following instructions.

Here is an example

Example of creating a Telegram bot
Example of creating a bot

Botfather allows you to edit other optional settings, like default commands, privacy settings, etc. You can find all available settings tapping the box containing a “/” while chatting with BotFather.

Once you get your token, and then you can instantiate your bot in your project doing this:

TelegramBot bot = new TelegramBot("YOUR-TOKEN");

Where the token is the one given by BotFather, and then you are ready to code your project and make your Telegram bot work.

You can use methods that you can find on Telegram Bots Api.
You can find some basic examples here.
You can download javadoc here: Telegram bot utilities javadoc
If you found a bug, or you need help, please comment this post and I will help you asap.

Next Entries Telegram Bots Utilities - examples

5 thoughts on “Telegram Bot Utilities – Java Library

  1. hi
    i have a problem with understanding of bot
    i know how to code but my question is should i build a software? a website using ssl? where should i upload my code? and when i uploaded in a direction how it works? for example i uploaded in http://www.example.com/testbot.php
    and then do what? is it work by it self? or is should something?
    i need a step by step instruction for a simple bot

    please help me!!
    i really need help

  2. Alessandro Pomponio on said:

    Hey leocus,
    First of all: great job with this library, it’s been very easy to use and it’s working great!
    I have found an issue, though. If i send a random string to my bot, the chat doesn’t have a title set (the JSON Object sent to the Chat constructor is something like this: {“last_name”:”Pomponio”,”id”:myID,”type”:”private”,”first_name”:”Alessandro”,”username”:”myUsername”}) so, when trying to parse the title (Chat.java at line 32), a JSONException is thrown and the rest of the object doesn’t get parsed. My suggestion would be surrounding the title parse with a try/catch, so you can catch the exception and move on.

    Thank you once again for your work, bravissimo 🙂

    Alessandro

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.