lukefx / hubot-telegram

Hubot adapter for Telegram
MIT License
160 stars 42 forks source link

Move the offset update into the getUpdates method. #43 #44

Closed arcturial closed 8 years ago

arcturial commented 8 years ago

To reduce duplicate messages, update the offset immediately when Telegram responds.

arcturial commented 8 years ago

Solves issue #43

@lukefx please review.

I will run this on my setup for a day or so to test for any errors and will merge when all are happy.

lukefx commented 8 years ago

With a fresh setup I'm getting endless messages from the bot... Strange...I'm using this code directly in my package.json

"hubot-telegram": "lukefx/hubot-telegram#issue-43"

arcturial commented 8 years ago

Updated. Wasn't properly setting the offset

arcturial commented 8 years ago

We can. However, if the handleUpdate method is slow it might hold up the loop. For example, if you receive 5 messages and handling each message takes 1 second. If your setInterval is 2 seconds, you will end up with atleast 2 duplicate messages. Does that make sense?

lukefx commented 8 years ago

We can. However, if the handleUpdate method is slow it might hold up the loop. For example, if you receive 5 messages and handling each message takes 1 second. If your setInterval is 2 seconds, you will end up with atleast 2 duplicate messages. Does that make sense?

yepp absolutely...aaaaand, what about move offset just to the last update_id without a loop?

self.offset = result[result.length-1].update_id if result.length

for msg in result
  self.handleUpdate msg
arcturial commented 8 years ago

That will work, will update the PR a bit later.