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

Idea for a new way to handle conversations #42

Closed
Kotov584 opened this issue Nov 14, 2023 · 3 comments
Closed

Idea for a new way to handle conversations #42

Kotov584 opened this issue Nov 14, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@Kotov584
Copy link

Is your feature request related to a problem? Please describe.
I'm always frustrated when I have to define conversations using input handlers.
When you are using input handlers, it's pretty hard to write and manage complex conversations.

Describe the solution you'd like
Instead of input handlers, we could use classes for defining conversations. So we are able to write more well-architected code, even when it is complex.

Example:

package com.example.blank.conversation

import eu.vendeli.tgbot.TelegramBot
import eu.vendeli.tgbot.api.message
import eu.vendeli.tgbot.types.User
import eu.vendeli.tgbot.types.internal.ProcessedUpdate

sealed class GreetingsConversation {
    object Start : GreetingsConversation() {
        fun handle(update: ProcessedUpdate, user: User, bot: TelegramBot) {
            message("Hello, let's move to second step!").send(user, bot)
            //set secondStep state
           //maybe something like 
           setData(user, "hello" to update.text)
           setState(user, GreetingsConversation::start)
        }
    }

    object SecondStep : GreetingsConversation() {
        fun handle(update: ProcessedUpdate, user: User, bot: TelegramBot) {
            // retrieve data from start step and proceed
            message("Nice job! You completed this.").send(user, bot)
            deleteState(user, GreetingsConversation)
        }
    }
}

Additional context
Not sure, if we can do this way.
We discussed about it in Telegram group.

@Kotov584 Kotov584 added the enhancement New feature or request label Nov 14, 2023
@Kotov584
Copy link
Author

or also this

package com.example.blank.conversation

import eu.vendeli.tgbot.TelegramBot
import eu.vendeli.tgbot.api.message
import eu.vendeli.tgbot.types.User

class GreetingsConversation {
    fun start(user: User, bot: TelegramBot) {
        message("Hello, let's move to second step!").send(user, bot)
    }

    fun secondStep(user: User, bot: TelegramBot) {
        message("Nice job! You completed this.").send(user, bot)
    }
}

@vendelieu
Copy link
Owner

Experimental implementation is released in #61

@vendelieu
Copy link
Owner

implemented in #75

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

No branches or pull requests

2 participants