Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The echo bot ignores the 1st message and replies to the 2nd, 4th, 6th, etc message #11

Closed
automaciej opened this issue Aug 18, 2016 · 8 comments · Fixed by #14
Closed

Comments

@automaciej
Copy link
Contributor

I compiled the echo bot example and it looks like this:

me: msg1
[no response from bot for a couple seconds]
me: msg2
bot: msg1 [immediate answer]
bot: msg2
me: msg3
[9 minutes pass]
bot: msg3

I would expect that the bot would answer right away to the 1st message.

@mrd0ll4r
Copy link
Owner

mrd0ll4r commented Aug 18, 2016

Hey, thanks for reporting the issue!

Do you use the webhook version or the long-pull version?

I just tested examples/echo.go with an old bot and a newly created bot and everything seems to work fine.

@automaciej
Copy link
Contributor Author

The long-pull version I guess, because I haven't exposed anything over the network. I only added a key to examples/echo.go and ran it. My bot is @MaciejBot.

@mrd0ll4r
Copy link
Owner

I tried your bot - are you maybe running behind something that could delay your HTTP requests?

Can you try replacing the two calls to fmt.Printf with log.Printf to see timestamps, then perform another request and post the logs?

@automaciej
Copy link
Contributor Author

2016/08/19 23:27:35 <-108, From:        209215060 (P) Mátchek Bliziński (@automaciej), Text: g 
2016/08/19 23:27:39 ->110, To:  209215060 (P) Mátchek Bliziński (@automaciej), Text: g
2016/08/19 23:27:39 <-109, From:        209215060 (P) Mátchek Bliziński (@automaciej), Text: h 
2016/08/19 23:27:39 ->111, To:  209215060 (P) Mátchek Bliziński (@automaciej), Text: h
2016/08/19 23:27:53 <-112, From:        209215060 (P) Mátchek Bliziński (@automaciej), Text: i 
2016/08/19 23:28:09 ->114, To:  209215060 (P) Mátchek Bliziński (@automaciej), Text: i
2016/08/19 23:28:09 <-113, From:        209215060 (P) Mátchek Bliziński (@automaciej), Text: j 
2016/08/19 23:28:09 ->115, To:  209215060 (P) Mátchek Bliziński (@automaciej), Text: j

This shows the example how the first "i" has no response, but when "j" arrives, "i" is replied back.

I noticed that when I press ctrl+C, it says "Closing…" and does nothing, does not return. But when I send it a message (while it is in the closing state), it immediately exits (after receiving a message).

@mrd0ll4r
Copy link
Owner

About the closing: That is the usual behavior, comes from the long polling we do with the Telegram API: We send a request /getMessages (or something like that) with a timeout (something like 60 seconds?) - The server keeps the request open for up to 60 seconds or until it has something to send back to us. So in your case, because you sent a message to the bot, this function returns and the bot exits. You don't lose any messages, this message will be sent again after you restart the bot, iirc.

About your logs: Yes, that's what I expected - the call to send a message is blocked for some reason.

After diggin into this a bit it seems like resty (the package we use for the API calls) has made a change that introduced this behavior. I just updated my packages and now have the same bug. I'll look into it, thanks a lot for reporting this!

@mrd0ll4r
Copy link
Owner

go-resty/resty#29 is what introduced the change.

@mrd0ll4r
Copy link
Owner

You can try the parallel-fix branch, should fix the issue. Gonna merge tomorrow or so :)

@automaciej
Copy link
Contributor Author

The parallel-fix branch fixes it, thanks! \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants