如何使用Botman.io创建松弛对话框

问题描述 投票:0回答:1

如何使用Botman在Slack中创建对话框?我使用Slack应用程序中的Botman创建了一个下拉菜单和按钮。但是从下拉列表中选择一个值后,我需要触发一个Slack对话框。我该如何实现?

php laravel bots slack
1个回答
0
投票

您可以在this commit中看到完整的实现。

首先,您必须扩展BotMan \ Drivers \ Slack \ Extensions \ Dialog类。例如:

<?php

namespace App\BotMan\Dialogs;

use BotMan\Drivers\Slack\Extensions\Dialog;

class TestDialog extends Dialog
{
    /**
     * Build your form.
     *
     * @return void
     */
    public function buildForm()
    {
        $this->title = 'Test dialog';
        $this->callbackId = 'test-dialog-callback-id';

        $this->text('Text', 'text');
    }
}

然后,您可以使用conversation的运行方法发送对话框:

<?php

namespace App\BotMan\Conversations;

use App\BotMan\Dialogs\TestDialog;
use BotMan\BotMan\Messages\Incoming\Answer;

class TestConversation extends Conversation
{
    public function run()
    {
        $response = $this->sendDialog(new TestDialog, function (Answer $answer) {
            $value = $answer->getValue()['text'];

            // ...
        });
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.