Closed n0mer closed 9 years ago
This is a limitation of the Telegram API itself https://core.telegram.org/method/messages.sendMessage#return-errors
It seems their API can only support 4096 bytes per message.
@lukefx, do you think it's worth limiting messages to that size so that they send multiple messages if the byte size is more than supported by Telegram?
Hi
Please try out the branch https://github.com/lukefx/hubot-telegram/tree/issue-17
You can include it in your package.json file like so:
"hubot-telegram": "lukefx/hubot-telegram#issue-17"
I have changed the sending code to split the messages into parts when they are above 4096 characters. Let me know if this solves your problem.
@arcturial okay, i'll check right now and respond how is it going :)
btw, here is the command to install that via shell
npm install --save "git://github.com/lukefx/hubot-telegram#issue-17"
so - it works, i'm getting 2 messages.
But, for some reason, i'm getting 2nd part as 1st message and 1st part as 2nd msg.
corresponding log records
Sep 6 01:04:03 sbg docker/e54ebf98f743[15891]: [Sun Sep 06 2015 01:04:03 GMT+0200 (CEST)] INFO Sending message to room: 815356
Sep 6 01:04:03 sbg docker/e54ebf98f743[15891]: [Sun Sep 06 2015 01:04:03 GMT+0200 (CEST)] INFO Sending message to room: 815356
Please try the latest commit on https://github.com/lukefx/hubot-telegram/tree/issue-17
I had to make the requests sequential since it seems that the message with more bytes gets delivered last possibly due to network latency (ie. since the smaller message gets sent to Telegram faster it is delivered first). This is unfortunately still a problem if you do two send
calls one after the other in your script. The one with the smallest packet will most likely be delivered first. However, for the scenario you described (where your bot sends a single request)...the messages should now deliver in the intended order even though it will be slightly slower than previously.
I tried, now order is fine, thanks.
One thing - response is delivered as "one message per one line of hubot response". Is it intended behaviour?
And, how will it work for single-line string longer than 4096 ?
Not sure I understand, the code splits the message using regex.
/.{1,4096}/g
Meaning that it should split the string based on any character for 4096 characters regardless of new lines etc. It should only send multiple messages if the character count of a string is more than 4096, otherwise it should work like it normally does. Does that answer you question?
this is how output looks like now
yesterday it looked like this
Ah, I understand
This might be the regex, standby while I fix.
just curious - did you run this code by yourself :) ?
Yeah, but I ran it with a test script that just adds a whole bunch of characters on a single line. I will create a test for multiple lines now.
okay, glad that my use case helped to corner this issue
I pushed another update with a test, hopefully I caught all the gremlins this time.
wow, now it is much better - both fast and in correct order :)
also newline is handled nice
i am not sure how do you actually split the text
but if you do it the way words are not trimmed in the middle of a single word - that's super )
Gosh, I will have a look at that...don't think I can use straightforward regex for it though :(
Well, this is not necessary. Especially if it will be implemented as long "hairy" regexp :)
I'm serious - please just truncate, w/out any regexp aimed to be smarter than regexp should be.
Let's merge what you already have into master
, and close this issue. Everything is already good enough and fast enough.
Ok, I merged it to master. I will update my own Hubot to user #master for a few days to see if any issues pop up. After this period I will tag a new official release. Thanks for the help with debugging this issue.
:+1:
As alternative we could check the length of the result string here: https://github.com/lukefx/hubot-telegram/blob/master/src/telegram.coffee#L105
because we join every message in one big string...couldn't just split there and do multiple send?
The strings...
entries could still be more than the allowed characters, which is why I combined it and then split it into appropriate chunks. Can you maybe provide and example of what you mean?
hi, got "message is too long" error
Same bot works well with
Slack
back-end.$ wc ~/temp/hubot-help.txt 72 915 5565 /Users/n0mer/temp/hubot-help.txt
So my
/help
mesage contains 72 lines, 915 words and 5565 chars