rubenlagus / TelegramBots

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

get bot username with token? #231

Closed Pie133 closed 7 years ago

Pie133 commented 7 years ago

Hi i want to know is this possible to get bot username with token ?

Clevero commented 7 years ago

What do you mean exactly?

In your application, there should be a getBotToken() and getBotUsername() method. The first one is required in order to run your bot. The second one can be helpful.

Another way to get the bot username would be getMe in the API. You can call getMe like all other functions of the Bot API, cause it's just a implementation of the offical Telegram Bot API.

try{
            User me = getMe();
            System.out.println("id: " + me.getId());
            System.out.println("firstName: " + me.getFirstName());
            /*
             * and
             * so
             * on
             * ...
             */

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

Hope this helps

Pie133 commented 7 years ago

i mean is there any function that i can insert the bot token and get bot username something like this: getBotUsernameFromToken("1234456:dfgsdkjgkuygkuyKHYKGygluhlyuy"); and then it return something like : @testbot

Clevero commented 7 years ago

Yes, getMe would be it.

The API doc states about getMe: A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object.

And "...basic information about the bot..." includes also the botusername as stated above.

Pie133 commented 7 years ago

I love you man :D

dapoldi commented 7 years ago

The flirting is strong with this one.

-------- Original message -------- From: Pie133 notifications@github.com Date: 5/12/17 23:36 (GMT+01:00) To: rubenlagus/TelegramBots TelegramBots@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [rubenlagus/TelegramBots] get bot username with token? (#231)

I love you man :D

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/rubenlagus/TelegramBots/issues/231#issuecomment-301191774, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AEagowXlj5F6QelNFMJ5S6cHOOqJJX4jks5r5NDZgaJpZM4NZZtw.