Open stormstricker opened 5 years ago
https://core.telegram.org/bots/api#sendmessage
On success, the sent Message is returned
https://core.telegram.org/bots/api#sendmessage
On success, the sent Message is returned
How would I check it using the telegrambots library though? SendMessage m = execute(sendMessage);
gives a Incompatible types. Required SendMessage but 'execute' was inferred to T: no instance(s) of type variable(s) exist so that Message conforms to SendMessage
error.
https://core.telegram.org/bots/api#sendmessage https://core.telegram.org/bots/api#message
Message
and SendMessage
are different things
Message msg = execute(new SendMessage(...));
https://core.telegram.org/bots/api#sendmessage https://core.telegram.org/bots/api#message
Message
andSendMessage
are different things
Message msg = execute(new SendMessage(...));
So would this check be correct?
org.telegram.telegrambots.meta.api.objects.Message m = null;
try {
m = execute(sendMessage);
}
catch (Exception e) {
if (m==null) {
//send again
}
}
I would say that if execute(...)
throws an exception, the SendMessage is not sent
Could you share the code where the opposite happens?
I would say that if
execute(...)
throws an exception, the SendMessage is not sent Could you share the code where the opposite happens?
The code is just the one above. An execute
inside try-catch block. I connect to Telegram through VPN so connection timeouts is a common thing. I've found that even checking if a m==null
doesn't prevent from sending duplicate messages - it seems that the first execute
sends a message, there happens connection timeout
exception, m
is somehow still null, so I send the message again, only to later receive too duplicate messages. Without checkout if m
is null, duplicate messages after connection timeout
exception are even more common.
I wonder, is execute
method asynchronous?
Extending the question above - since the send() calls use Apache commons, would it be possible to set the timeout for calls globally? I am having unexpected waits when I send photos using sendPicture(URL) signature, hence the need.
@forrestrunning Just override your custom implementation of BotOptions and should be done:
Sometimes there are connection issues, so execute() method throws an exception. A message might or might not get sent. I tried including another call to send message method in the catch block, however, if a message managed to get delivered successfully, despite the exception, it results in a duplicate message being sent. Is there a way to check if the message has been sent? execute() doesn't seem to return a boolean, only type T.