无法响应交互式消息的多次单击

时间:2018-05-31 05:00:01

标签: laravel bots slack

我希望能够从以下位置检索回复: a)频道上有很多人 b)确定选择了哪个选项的用户

出于某种原因,在第一个人点击之后,之后任何回复都会进入后备。

我将如何实现这一目标?这是我的档案

这是我的控制器页面: -

namespace App\Conversations;
namespace App\Http\Controllers;

use App\Conversations\ExampleConversation;
use App\Conversations\MenuConversation;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\Drivers\Slack\Extensions\Menu;
use GuzzleHttp\Client;
use Illuminate\Http\Request;


class BotSlackController extends Controller
{


    public function getSlackUsers()
    {
        $guzzle = \App::make(Client::class);

        $user_data = [];
        $slack_token = "xoxb-2893074844-363165652051-cCiOK0lMGHf5e72QF6s04Nbl";
        $user_list_url = "https://slack.com/api/users.list?token=$slack_token&pretty=1";

        $user_list = $guzzle->request('GET', $user_list_url)->getBody()->getContents();

        $user_list = json_decode($user_list);
        if (!empty($user_list->members)) {
            foreach ($user_list->members as $user_info) {
                if ($user_info->deleted == true) {
                    continue;
                }
                $user_data[] = ['id' => $user_info->id, 'name' => $user_info->real_name];
            }
        }
        return $user_data;
    }

    public function sendMessageView()
    {
        $slack_users = $this->getSlackUsers();
        return view('slackMessage', ['slack_users' => $slack_users]);
    }

    public function sendControllerBot(Request $request) {
        /*$data = \App::make(ExampleConversation::class);
        $data->sendBot($request);*/

        $botman = app('botman');
        $user_id = $request['slackUserId'];
        $user_msg = $request['slackMessage'];

        $botman->startConversation(new MenuConversation(),$user_id,\BotMan\Drivers\Slack\SlackDriver::class);

        //$botman->listen();
    }


}

这是我的MenuConversation文件: -

<?php

namespace App\Conversations;

use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use BotMan\BotMan\Messages\Conversations\Conversation;

class MenuConversation extends Conversation
{


 public function askBtn()
    {
        $question = Question::create("Hello, How are you?")
            ->fallback('Unable to create a new database')
            ->callbackId('ask_btn')
            ->addButtons([
                Button::create('I am fine')->value('fine'),
                Button::create('Not good')->value('no_good'),
                Button::create('Do not disturb')->value('wont_disturb')
            ]);


        return $this->ask($question, function (Answer $answer) {
            if ($answer->isInteractiveMessageReply()) {
                $result = $answer->getValue();
//Will actually store it in a DB and yet to figure how to retrieve the Slack User that selected the option
            /\* $this->say("Hello I got your response. Response: ".$result); \*/
                $this->bot->reply("Hello I got your response. Response: ".$result);
            }

        });

    }

       public function run()
    {
        $this->askBtn();
    }
}

当我第一次点击任何按钮时,我得到了我点击的按钮的值,但在第二次点击后立即转到我在botman.php创建的回退功能。

请有人帮我解决这个问题。

  1. 如何获得多响应(或多次点击响应)
  2. 如果我在公共频道而不是特定用户中发送消息,我如何获取点击该按钮的用户ID。

0 个答案:

没有答案