Telegram is a pure HTTPS platform so you can use a lot of languages or tools:

  • php

  • java

  • python

  • go

  • curl

  • httpie

  • …​

I’ve developped a simple java library using Micronaut’s http-client module but you can build your own library.

Token

micronaut-telegram-api required an environment variable called TELEGRAM_TOKEN or a property telegram_token with the token of the bot

TelegramBot

TelegramBot is a micronaut http-client, configured with the TELEGRAM_TOKEN property, to send messages to a channel, to an user, etc

Dependency coordinates

implementation group: 'com.puravida.telegram', name: 'mn-telegram-api', version: '0.3.2'

Example

You need to inject it into your serviceS :

class SomeService{

    TelegramBot telegramBot;

    SomeService(TelegramBot telegramBot){
        this.telegramBot = telegramBot;
    }
}

Send Message

To send a message we use the micronat-telegram-api Message class:

    void sayHello(String chatId){
        Message message = new Message();
        message.setChat_id(chatId);
        message.setText("hello world");
        telegramBot.sendMessage(message).blockingGet();
    }
    void sayHello(String chatId){
        telegramBot.sendMessage(
            new Message(chat_id:chatId, text:'Hello world')
        ).blockingGet();
    }

Next