rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.72k stars 1.19k forks source link

How to listen for not bot messages — account messages. #1179

Open dynoChris opened 1 year ago

dynoChris commented 1 year ago

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";
    }

}
zortan3301 commented 1 year ago

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

samosxin commented 1 year ago

you need telegram TD lib