miguelgrinberg / Flask-SocketIO-Chat

A simple chat application that demonstrates how to structure a Flask-SocketIO application.
http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent
MIT License
676 stars 242 forks source link

#question: adapting your example to a chatbot server #11

Closed alexDeCastroAtGit closed 5 years ago

alexDeCastroAtGit commented 7 years ago

Hi Miguel, thanks for posting this neat example. I'm flask newbie who's learning the ropes through your tutorials and book.

I have a "back-end" code that takes as input free-form text and classifies the corresponding intent. It's a basic sklearn-kit model.

I'm trying to adapt your code to have a person chatting with the bot (which will have a hard-coded waterfall on top of the ML logic to emulate some basic interaction).

What I'm trying to do (for a prototype) is to have the conversation thread bot-human displayed in a window as per your example -- I'd like messages appended on the same screen.

Do I need to connect the bot the chat room? Any pointers or resources to look at are very welcome.

Anyhow, I'll keep plodding along. Many thanks, Alex

miguelgrinberg commented 7 years ago

If the chat is between a single client and a server-controlled entity (i.e. your bot), you do not need to use rooms. The server can send a message directly to any client, by simply using the session id of the client as the room name. This is the request.sid argument that you get when you are handling an event from the client. Typically people capture request.sid in the connect event handler and associate it with the user in a database.

alexDeCastroAtGit commented 7 years ago

Thanks! I'll give it a shot today. Consider this issue closed.

miguelgrinberg commented 5 years ago

This issue will be automatically closed due to being inactive for more than six months. Seeing that I haven't responded to your last comment, it is quite possible that I have dropped the ball on this issue and I apologize about that. If that is the case, do not take the closing of the issue personally as it is an automated process doing it, just reopen it and I'll get back to you.