botman / driver-facebook

BotMan Facebook Messenger Driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getText returns Value instead of text in Question Answer for quick replies

allandereal opened this issue · comments

After "if $answer->isInteractiveMessageReply()",
the selected quick reply button's value can be accessed by $answer->getValue,
and the selected button's text should be accessed by $answer->getText. (this worked in the old version)
This is not the case with the new botman version. The $answer->getText returns the value of the button instead of the actual text.
So in a nutshell, both methods return the same value! for $answer->getValue!
@mpociot may you please look into that, thank you.

Hey @allandereal , I am not sure where you see the problem. If someone clicks the button, you will get the correct value with getValue. If someone types text instead using the button, you get the correct value with getText. It maybe a little confusing that you get by click on the button also the value with getText, but I would see it is not wrong.

@christophrumpel maybe you dont get me quite well. So my main concern is that before botman 2.0, when one clicked a quick reply button in facebook messenger, getValue() would get the payload value and getText() would get the payload text not the free type text. But with the new botman, getText() returns what getValue() returns on button click. please consider the example below.
$this->ask($question, function (Answer $answer) { // Detect if button was clicked: if ($answer->isInteractiveMessageReply()) { $selectedValue = $answer->getValue(); //works! $selectedText = $answer->getText(); //should return payload text but returns value instead! }else{ //this is if someone types freely and didnt click the button (#This is not where my concern is though#) } });

So if I understand you correct, you want to get the buttons' text with getText() when someone clicked the button, right? And if yes, can you tell me why you need the button's text?

@christophrumpel Yes. I am working on a chatbot that uses the selected text instead of the value. I know i can find a work around this but i would prefer if i could get it with $answer->gettext() just like it was the case with botman versions <2.0.
More so, my code won't break or show undesirable results if i updated my botman version.

I see and I understand it. But if we would change that, it would be a breaking change for everyone else. Maybe that would be something for the next major version @mpociot ? But for now I don't see an easy solution here for you =/

Mh... According to the docs the desired behavior should be exactly how @allandereal described.

The following code snippet is from https://botman.io/2.0/conversations Chapter "Asking Questions"

$question = Question::create('Do you need a database?')
    ->addButtons([
        Button::create('Of course')->value('yes'),
        Button::create('Hell no!')->value('no'),
    ]);

$this->ask($question, function (Answer $answer) {
    if ($answer->isInteractiveMessageReply()) {
        $selectedValue = $answer->getValue(); // will be either 'yes' or 'no'
        $selectedText = $answer->getText(); // will be either 'Of course' or 'Hell no!'
    }
});

Here $answer->getText() returns the button's text and not the value.

So either the docs should be updated or the facebook driver 🤓

Ok so I checked this now in detail. Originally, it was supposed to work like you said and like mentioned in the docs. But this is different for every driver. For example, for Telegram, it is not possible to get the button text. But for Facebook it is and I changed it like seen here: 5ccdd07

I just can't tag a new release, since this change would be a breaking change and need to wait for 2.0. Not sure if it makes sense to release it just for this change. Thanks for your details on that.