TelegramBots icon indicating copy to clipboard operation
TelegramBots copied to clipboard

How to listen for not bot messages — account messages.

Open dynoChris opened this issue 2 years ago • 2 comments

Hi! I made my first Telegram bot. It's able to listen for new messages in the Telegram bot (BotFarther), code below, but I need to listen for new messages on my Telegram account! Not bot! How to do it help me please!

package org.example;

import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;

public class Main {
    public static void main(String[] args) {
        try {
            TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
            MyBot bot = new MyBot();
            telegramBotsApi.registerBot(bot);

        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
}

class MyBot extends TelegramLongPollingBot {
    @Override
    public void onUpdateReceived(Update update) {
        System.out.println("Hello World");
    }

    @Override
    public String getBotUsername() {
        return "BOT_USERNAME";
    }

    @Override
    public String getBotToken() {
        return "BOT_TOKEN";
    }

}

dynoChris avatar Jan 08 '23 01:01 dynoChris

Telegram prohibits using personal accounts as bots, you can only create a bot through BotFather

zortan3301 avatar Jan 29 '23 10:01 zortan3301

you need telegram TD lib

samosxin avatar Aug 21 '23 03:08 samosxin