jgorset / facebook-messenger

Definitely the best way to make Bots on Facebook Messenger with Ruby
MIT License
962 stars 211 forks source link

clear cached body on new request #245

Closed zhum closed 5 years ago

zhum commented 5 years ago

I've found that in my simple bot only first message from fb-messenger was successful, each later message got message integrity error. When I insert cleaning of @body and @parsed_body all become ok.

jgorset commented 5 years ago

Hi @zhum! Thanks for raising this. I can't quite make sense of it, though -- as far as I can tell a new instance of Facebook::Messenger::Server should be created for each request, and so all this change should do is invalidate the request body cache within a single request.

What sort of integrity error are you getting exactly, and how are you mounting the server in your Rack application? If you could share your full code, I'd like to take a look at it.

zhum commented 5 years ago

Thank you a lot! I'm developing a multi-messenger chat bot. Here it is: https://github.com/zhum/telebot Shortly: all messengers adapters are incapsulated in separated classes, inherited from TeleLoop (lib/tele_loop). Main application starts a thread with new instance of adapter and calls 'go' method. Then adapter is listening for messages and should be able to send notifications if they would appear in special queue (start_async method starts queue listening in separated thread and async_process method is called on each new external message). Here are two another adapters for console (just connect to unix socket via nc) and Telegram, you can check the logic. May be I use your gem wrong way :)

jgorset commented 5 years ago

Okay, so I think what you need to do is to make sure that you have a new instance of Facebook::Messenger::Server for each request. That way, nothing will carry over between requests.