I want a Telegram bot notify me when a user do some action in my website. I have been testing Telegram bots to send messages and using getUpdates via polling to receive, and everything works perfectly. I have read than the polling method consume more CPU than webhooks (because it is constantly checking for new messages), but this is more complicated to implement, so I discard webhooks.
Actually, I don’t need to use the polling or webhooks, because what I want is to send messages, but I have to implement the getUpdates method compulsory. Is there any way to use only the send message function and avoid the receive messages? Like a only-read bot or a telegram channel.
Thanks!
EDIT. Here is my code in Java:
public class TelegramBot extends TelegramLongPollingBot {
@Override
public void onUpdateReceived(Update update) {
// Stuff when the bot receive a message
// I don't need this method, but it is compulsory to implement it
}
public synchronized void sendMsg(String msg) {
// Stuff to send a message
// Here goes the code I only need
}
@Override
public String getBotUsername() {
// Compulsory to implement
return "my_bot_user_name";
}
@Override
public String getBotToken() {
// Compulsory to implement
return "my_token";
}
}
2
Answers
I have solved all using Jersey WS (
jersey-client
andjersey-common
packages)This is how my code looks now, just calling it when I need it and not polling at all:
It is possible to configure and start the chatbot without actually performing the polling
In this case there is no polling but a message is sent to the chat.
Notice: