Wait for a response from a User

Hello, I am building a Telegram bot and a functionality I would like to add is some kind of comfirmation, I could make it work with commands but I would like to make it more “interactive”, for example:

User: "I'd like to listen to Jazz"
Bot: "Do you really want to listen to Jazz?"
User: "Yes"
... # Send more things related to the answer.

I was thinking on maybe saving the command that the user sent in state and then check for the next message sent after that, I’d have to clean the state after that I guess but I don’t know how that can conflict with other people if maybe someone else sends a message at the same time, maybe I should spawn a process for each user?

I was also thinking about using Task and await for the next message of the user? I’m not sure how can I implement it. The first option seems better for me but how I said, I don’t know what kind of problems it could bring in the long run if any. I’m looking for implementation options here if anyone can help me :slight_smile:

Since telegram is mostly one to one, I’d spawn one process per conversation.

1 Like

But would you implement it how I said? I’m thinking about a way to wait for the response of the user and do different actions based on that.

Just a GenServer is perfect for this. Spawn one for each user and the user sends messages to it and you respond as however you want.

1 Like

I was on my mobile when I wrote the first answer, so I kept it short and only talked about the question that seemed more important to me.

The other thing… Well I do not really understsand what you mean… Unless you have really hardcoded and strictly specified sentences which do not change in the slightliest, just treat the sentences as commands then, the last one to put in the state, along a small context, then just wait for the answer.

If you wan’t a naturally speaking bot ala googles allo, do your master in CS, psychology and your target language first. Each. Perhaps you can omit psychology, but I’m not sure about that. Also use the time during study to gather people around you that can help you.

Processing natural language is nothing you do in your freetime. Not even in your dayjob if you have to ask how to do it… Sorry to say it this direct way, but listen to me know, might save you a lot of time and money.

The way you have to keep the state and context, does massively deepend on what kind of language you want to process. A wellthought formal language in such a system can get implemented pretty much like an automata, but natural language does need so much context, spanning even hours to get understood correctly…

2 Likes

Thanks, I just wanted to see if there was another solution that would fit better but a GenServer that is!

1 Like

The answers are hard coded, the user has to answer “Yes” or “No”, I just wanted to know how to keep track of this to wait for a response and do another action based on that, thanks!

Then a “simple” state machine might be the way to go. There was a library
which abstracted one over genserver, but I’m not sure right now how it’s
named.

Miguel noreply@elixirforum.com schrieb am Di., 13. Juni 2017, 20:18:

1 Like

there’s a lot done around NLP that can be of help to a non-expert building a chat bot, don’t need to be so pessimistic :slight_smile:

1 Like

https://www.luis.ai

https://wit.ai

1 Like

Cool… It wasn’t when I wanted to do it… Well was pre 2k… Also it may be that I didn’t knew the correct terms to search for…

1 Like