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

Error at sendMessage #9

Closed SuperMasterBlasterLaser closed 8 years ago

SuperMasterBlasterLaser commented 8 years ago

When I use method with callback:

  locationCommand.locationHandlerMethod(userDocument, message.getLocation(), new ResultCallback() {
        @Override
        public void onResult(String message) {
            SendMessage messageToSend = new SendMessage();
            messageToSend.setChatId(userDocument.getString("chat_id"));
            messageToSend.setText(message);
            messageToSend.enableHtml(true);
            try {
                sendMessage(messageToSend);
            } catch (TelegramApiException e) {
                e.printStackTrace();
            }

        }
    });

Exception happens on sendMessage method:

 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
 SLF4J: Defaulting to no-operation (NOP) logger implementation
 SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
 org.telegram.telegrambots.TelegramApiException: Error at sendmessage
at org.telegram.telegrambots.bots.AbsSender.sendApiMethod(AbsSender.java:435)
at org.telegram.telegrambots.bots.AbsSender.sendMessage(AbsSender.java:51)

Why this exception happens? Is there any option to disable this StaticLoggerBinder @rubenlagus ? I also use async version of MongoDB Java driver.

UPDATE

I have added SLF4J and configured. However, I still get error at sendMessage:

  org.telegram.telegrambots.TelegramApiException: Error at sendmessage
at org.telegram.telegrambots.bots.AbsSender.sendApiMethod(AbsSender.java:435)
at org.telegram.telegrambots.bots.AbsSender.sendMessage(AbsSender.java:51)
at my.MyBotHandler$3.onResult(MyBotHandler.java:173)
at my.structure.commands.location.NearestATMSLocationCommand$1.sendResult(NearestATMSLocationCommand.java:69)
at org.asynchttpclient.AsyncCompletionHandler.onCompleted(AsyncCompletionHandler.java:64)
at org.asynchttpclient.netty.NettyResponseFuture.getContent(NettyResponseFuture.java:173)
at org.asynchttpclient.netty.NettyResponseFuture.done(NettyResponseFuture.java:210)
at org.asynchttpclient.netty.handler.HttpProtocol.finishUpdate(HttpProtocol.java:198)
at org.asynchttpclient.netty.handler.HttpProtocol.exitAfterHandlingBody(HttpProtocol.java:399)
at org.asynchttpclient.netty.handler.HttpProtocol.handleHttpResponse(HttpProtocol.java:434)
at org.asynchttpclient.netty.handler.HttpProtocol.handle(HttpProtocol.java:473)
at org.asynchttpclient.netty.handler.Processor.messageReceived(Processor.java:85)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.handler.stream.ChunkedWriteHandler.handleUpstream(ChunkedWriteHandler.java:142)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.handler.codec.http.HttpContentDecoder.messageReceived(HttpContentDecoder.java:108)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:459)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:485)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.handler.codec.http.HttpClientCodec.handleUpstream(HttpClientCodec.java:92)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:310)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

There is no proper description of what is happening.

UPDATE: I have found why this error is happening

Telegram has message length limit, which is 4096 symbols. My messages where more than 6000 symbols.

Your Bot API does not handle this error explicitly it just says ERROR HAPPENED and thats all. I spend 4 hours thinking that error is happening because of other libs.

Please add proper error message to this condition!

rubenlagus commented 8 years ago

@SuperMasterBlasterLaser The TelegramApiException thrown should have a field called apiResponse that must contain the exact response from Telegram servers, regardless which one it is. If you handle it, you should be able to access that field with the description, can you check?

SuperMasterBlasterLaser commented 8 years ago

@rubenlagus I think this apiResponse should be added to Exceptions message string.

rubenlagus commented 8 years ago

@SuperMasterBlasterLaser Why don't you just call getApiResponse() method in the exception to get the answer (if present) ? I don't think the full apiResponse should be added to the message as it is not always needed to find out the reasons..

SuperMasterBlasterLaser commented 8 years ago

@rubenlagus Maybe not full apiResponse message itself, just simple 3-4 word summary. What do you think about it?