这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@alies-dev
Copy link
Collaborator

@alies-dev alies-dev commented May 10, 2024

Allow switching from one Dialog to another

Needed in rare cases. Experimental. Can be removed in any minor release.

final class ShowQuestionDialog extends Dialog
{
    use DialogHelpers;
    use ShowStatistics;

    private const CB_SKIP_QUESTION = 'skip_question';
    private const CB_SEND_ANSWER = 'send_answer';

    protected array $steps = [
        'processAnswer',
    ];

    public function processAnswer(Update $update): void
    {
        if ($update->callback_query instanceof CallbackQuery) {
            if (str_contains((string) $update->callback_query->data, self::CB_SKIP_QUESTION)) {
                $this->bot->answerCallbackQuery(['callback_query_id' => $update->callback_query->id, 'cache_time' => 2]);
                SwitchToAnotherDialog::to(new SkipQuestionDialog($this->getChatId(), $this->bot));
            }
            throw new \LogicException("Unknown callback_query $update->callback_query");
        }

        $this->remember('answer', $update->getMessage()->text);
        ...

@alies-dev alies-dev self-assigned this May 10, 2024
@alies-dev alies-dev merged commit 6be552e into master May 10, 2024
@alies-dev alies-dev deleted the SwitchToAnotherDialog branch May 10, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants