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

Interactive Message buttons not working #50

Open
TheFrankman opened this issue Aug 16, 2019 · 11 comments
Open

Interactive Message buttons not working #50

TheFrankman opened this issue Aug 16, 2019 · 11 comments

Comments

@TheFrankman
Copy link

TheFrankman commented Aug 16, 2019

Hello There,

I'm having some issues with interactive buttons in a conversation.

I have copied everything relevant from botman studio and everything is working with the exception of buttons and menu list interactions.

When i click a button, i get by fallback message '' Sorry i don't understand that command " As apposed to responding with a joke or quote.

I'm sure i'm missing a configuration or something, but I can't for the life of me figure out what the issue is.

route/botman.php

<?php
use App\Http\Controllers\BotManController;

$botman->hears('Hi', function ($bot) {
    $bot->reply('Hello!');
});

$botman->hears('Start conversation', BotManController::class.'@startConversation');

$botman->fallback(function($bot) use ($actions) {
    $bot->reply("Sorry i don't understand that command");
});

Botman controller

    /**
     * Place your BotMan logic here.
     */
    public function handle(Request $request)
    {
            $botman = app('botman');
            $botman->listen();
    }

    public function startConversation(BotMan $bot)
    {
        $bot->startConversation(new ExampleConversation());
    }

Example conversation

<?php

namespace App\Conversations;

use Illuminate\Foundation\Inspiring;
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;
use Illuminate\Support\Facades\Log;

class ExampleConversation extends Conversation
{
    /**
     * First question
     */
    public function askReason()
    {
        $question = Question::create("Huh - you woke me up. What do you need?")
            ->fallback('Unable to ask question')
            ->callbackId('ask_reason')
            ->addButtons([
                Button::create('Tell a joke')->value('joke'),
                Button::create('Give me a fancy quote')->value('quote'),
            ]);

        return $this->ask($question, function (Answer $answer) {
            Log::info("Is interactive reply ? " . $answer->isInteractiveMessageReply());
            $this->say("Is interactive reply ? " . $answer->isInteractiveMessageReply());
            $this->say($answer->getValue());
            if ($answer->isInteractiveMessageReply()) {
                Log::info("Inside interactive message reply");
                Log::Info("Answer value : " . $answer->value());
                if ($answer->getValue() === 'joke') {
                    $responseContent = file_get_contents('http://api.icndb.com/jokes/random');
                    Log::info($responseContent);
                    $joke = json_decode($responseContent);
                    $this->say($joke->value->joke);
                } else {
                    $this->say(Inspiring::quote());
                }
            }
        });
    }

    /**
     * Start the conversation
     */
    public function run()
    {
        $this->askReason();
    }
}
@TheFrankman TheFrankman changed the title Interactive Message buttons not firing Interactive Message buttons not working Aug 16, 2019
@udovicic
Copy link

Any chance someone found workaround for this?

@TheFrankman
Copy link
Author

I gave up.

@brunohulk
Copy link

I'm having the same issue, has someone by any chance found the reason?

@johnson-jnr
Copy link

Hi, not sure about the slack driver but I had the same problem when testing locally using ngrok. I hosted on heroku and now the buttons are working fine.

@Evi444
Copy link

Evi444 commented Oct 20, 2020

I had a similar problem, solved updating opis/closure
https://packagist.org/packages/opis/closure

@rxng
Copy link

rxng commented Oct 22, 2020

This is a real issue - what is the point of asking questions when you can't click the answers and get a reply? Or maybe we are missing something...

@Evi444
Copy link

Evi444 commented Oct 22, 2020

It works up to php 7.2.33
Read they are working on a new version, mean while try updating opis/closure.
I got it working with php 7.4

@rxng
Copy link

rxng commented Oct 22, 2020 via email

@Evi444
Copy link

Evi444 commented Oct 22, 2020

I just realized that I was already running opis 3.6 on server with php7. 4 🙄
I had another server with php7. 2 in this one buttons worked fine.

It was after copying files from 7.2 to 7.4 server and trying to update with composer that buttons started working on new version.
Still have to check why, hope it gives a clue....

@SidneyHodieb
Copy link

Do a composer update in your project, it will update all the depencies, after that it will work correctly

@aaronware
Copy link

I know this is super late to this issue. But when I came across this earlier today playing around with the library, what I ended up doing was creating a new custom driver that extended the slack driver. Override the buildPayload method with your own and simply do the following...

		```$payloadData = stripslashes( $request->request->get('payload' ) );
		$payloadData = json_decode( $payloadData, true );```

The reason why it's failing is that the data passed from Slack is escaped in the send so json_decode can't read is properly and will return NULL by default unless the slashes are removed. Once doing that it works as intended.

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

No branches or pull requests

8 participants