rubenlagus / TelegramBots

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

send message #204

Closed zJudGenie closed 7 years ago

zJudGenie commented 7 years ago

How to send message on bot enable ?

Sorry for my bad english

Clevero commented 7 years ago

Do you mean when a user starts a new chat with your bot?

If so, just check if the message contains "/start"

zJudGenie commented 7 years ago

No, on startup on startup you must send me a message

MonsterDeveloper commented 7 years ago

You mean when you run your bot (maybe .jar), bot must send a message to a specific user that the bot has started?

zJudGenie commented 7 years ago

Yes, you must send a message to a chat id specified in the code

Mohandesr commented 7 years ago

Hope this useful when you get an update:

sendMessage(new SendMessage() .setChatId(update.getMessage().getChatId()) .setText("THIS IS MY TEXT") .setReplyToMessageId(update.getMessage().getMessageId())); <-(OPTIONAL)

zJudGenie commented 7 years ago

No, you must send the message when you start the bot and as soon as it receives an update

zJudGenie commented 7 years ago

@rubenlagus

rubenlagus commented 7 years ago

Why don't you use the sample case? https://github.com/rubenlagus/TelegramBots/wiki/Getting-Started#build-our-first-bot

zJudGenie commented 7 years ago

The bot works but I want to do, Which sends a message upon starting and not on receipt of a message or an update

djatoyz commented 7 years ago

can run in super group or just standard group @rubenlagus?

rubenlagus commented 7 years ago

@CrazyminerMC just execute the "sendMessage" method when you want. No need to wait for an incoming update. In the sample case, you could add something like this to the Main.java:

        ApiContextInitializer.init();

        TelegramBotsApi botsApi = new TelegramBotsApi();

        try {
            MyAmazingBot mybot = MyAmazingBot();
            botsApi.registerBot(mybot);
            SendMessage message = new SendMessage()
                .setChatId("XXXXXXX")
                .setText("Hello World!");
            mybot.sendMessage(message);
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
zJudGenie commented 7 years ago

Thank you so much, I wanted to do just that

Sorry for my bad english

devendrasingh17 commented 5 years ago

I want to send message to user when he/she register on my website, like i do not want user to start chat first, i want bot to start chat first.

Clevero commented 5 years ago

That's not possible. Users need to start a Chat first, for Spam reasons

But you can give them a link like https://telegram.me/BOT_USER_NAME?start=your_unique_id_of_user_in_your_application

That will open the Chat with your bot

devendrasingh17 commented 5 years ago

Isn't there any API from Telegram to send message with or without bot?

Clevero commented 5 years ago

You could use the normal API of Telegram for that, but that was not designed for bots.

https://github.com/rubenlagus/TelegramApi

devendrasingh17 commented 5 years ago

Can this API send message to user? like i want to send message to user when he/she register on my site

On Tue, Dec 4, 2018 at 2:03 PM Clevero notifications@github.com wrote:

You could use the normal API of Telegram for that, but that was not designed for bots.

https://github.com/rubenlagus/TelegramApi

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rubenlagus/TelegramBots/issues/204#issuecomment-444014870, or mute the thread https://github.com/notifications/unsubscribe-auth/ApY34PFKLh8wWAgqGTG-PTxe016GN2lVks5u1jNygaJpZM4Md7zZ .

-- Regards

Devendra Singh| Tejora Private Limited | Cell: +919799990168| Office: +91-22-40780780

devendrasingh17 commented 5 years ago

I do not want create telegram like application.