-
Notifications
You must be signed in to change notification settings - Fork 470
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
Conversations/dialogues #329
Comments
Check out and try |
OnText event fires every time user textes to bot. My task is just to ask two questions one-by-one and get for them answers. There is Rust telegram framework, where this is realized: https://github.com/teloxide/teloxide#dialogues-management |
You have to handle the input on your own. As you have the state of the user, you know in your However, we also planned to integrate similar to |
cool, thanks a lot! |
@demget What if the data expected from user is mixed, e. g. photos, texts & inline callbacks? Example:
I feel like this could be done with some catch-all handler but then the entire application would be a single handler function with a huge batch of IF-s. Any ideas if it would be possible to have some sort of "sub-handlers"? E. g. reroute the message within the handler into one of few child handlers based on the data received & the state of the user. This could be achieved by allowing handlers to be structs that contain CanHandle & Handle properties. |
idk if the dialogue system is done already, but back in my time, I used database to store current dialogue level (you can use whatever you want: file, redis, etc.), and, depending on that level, responded with different responses explanation: you can also do some sort of middlewares yourself to validate input and other fancy stuff :) but check for a dialogue system in docs, because the repo creator said it should be done until v3 been released |
@sinnrrr @demget Actually a lot of this would be achievable if there was an overloaded version of Handle like this: type Handler struct {
CanHandle func(m *tb.Message) bool
Handle func(m *tb.Message)
} This way, it would be possible to build any sort of complexity like this: // Handler that waits for a photo, than asks for a description, that asks the user to confirm submission.
// "step" can be stored in a database.
bot.Handle(Handler{
CanHandle: func(m *tb.Message) bool {
switch step {
case "upload_photo":
return m.Photo != nil
case "enter_description":
return m.Text != ""
case "confirm":
return m.InlineID != ""
default:
return false // We're done (or not yet started) here, go to the next handler
}
},
Handle: func(m *tb.Message) {
switch step {
case "upload_photo":
processPhoto(m) // Store photo, send "Enter photo description:" message to user
step = "enter_description"
case "enter_description":
processDescription(m) // Store description, send "Are you sure you want to submit this photo? [Save]/[Cancel]" buttons to user
step = "confirm"
case "confirm":
processConfirm(m) // Send "Thank you!" message to user
step = ""
}
},
}) EDIT: It would be even cooler if |
you can see how I had realised this in my repo: https://github.com/sinnrrr/schoolhelper |
@sinnrrr Thanks for the example. It really looks good however it doesn't allow the bot to accept different types of messages on different stages/levels/whatever-you-call-them. :) |
I'm not really sure what do you mean by "different type of messages". It's just the way you define how you handle dialogue level ( By the way, you should also have a look at the link, which is in the description of the issue to the rust library for telegram bots. The dialogue system is just so elegant there. |
@sinnrrr What I mean is https://github.com/sinnrrr/schoolhelper/blob/master/dialogue.go#L37 - won't the "OnText" event allow the dialog to handle only text inputs? Edit (offtop): looks like your bot really loves Ukrainian "salo" (I do, too) :D |
yes, I understood what did you mean I think it should be realized using levels, but not just 0 or 1 as an index, but text1 or inline2, that way tou can add more events like onInline (idk if that exists xD) and than switchcasing. but that is a real crap)) |
In func onHello(c tele.Context) error {
if c.Callback() != nil {
return c.Edit("Hello!")
}
return c.Send("Hello!")
// or simply:
return c.EditOrSend("Hello!")
} |
Is there any ability to handle user input?
For example, request user to enter his name and handle it.
The text was updated successfully, but these errors were encountered: