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

Facebook Generic template. Code inside the $this->ask method is not working. I guess, problem on the Botman side!!! #1205

Open
IljaPHP opened this issue Sep 25, 2020 · 0 comments

Comments

@IljaPHP
Copy link

IljaPHP commented Sep 25, 2020

  • BotMan Version: master
  • PHP Version: 7.3
  • Messaging Service(s):
  • Cache Driver: Filesystem

Description:

I was trying to do item listing by 10 items. In the each 10th item I add "Show more variants" button. This button is not working! I see first 10 items in the facebook chat. As I see by the log, there is no any answer from the facebook! Loging inside the "ask" method is not working! By this reason, I think that code inside inside the "ask" method is not working.
I don't know why.

I have function like this without facebook tempetes. Just buttons. It's working great! Just facebook generic template is not working. (( Please, help me!

 /**
    * @param $items
    * @param $first
    * @return object
    * @throws \Exception
    */
   public function showItemsListFacebookType($items, $first = 0) 
   {
      if (!count($items)) {
         $this->say('Elements is not found!');
         $this->showCommands();
      }

      $allCount = count($items);
      $counter = 0;
      $elements = [];
      foreach ($items as $item) {
         $counter++;
         if ($counter < $first) continue;
         if (($counter - $first) == 10) {
            break;
         }

         $date = new \DateTime($item->datetime);
         $timeString = $date->Format('h:i');
         if (in_array($timeString, ['03:30', '03:30'])) $timeString = 'TBA';
         $state = $item->state ? $item->state->abbreviation : '';
         $abbreviation = $item->state->abbreviation ? ', ' . $item->state->abbreviation : '';
         $cityAndState = $item->city->name . $abbreviation;

         $element = Element::create($item->name)
            ->subtitle("{$date->Format('d')} {$date->Format('M')} {$date->Format('Y')}, {$timeString}
            {$item->country->name}, {$cityAndState}, {$item->place->name}, {$item->place->address}")
            ->addButton(ElementButton::create('Get tickets!')
               ->url($item->url)
            );
         if (($counter - $first) == 9 && $allCount > $counter) {
            $element->addButton(ElementButton::create('Show more variants!')
               ->payload('showmore')
               ->type('postback')
            );
         }
         $elements[] = $element;
      }

      $question = GenericTemplate::create()->addElements($elements);

      \Yii::warning('Counter ' . $counter . ' allCount ' . $allCount);
      $this->ask($question, function (Answer $answer) use ($items, $counter) {
         $selectedValue = $answer->getValue();
         \Yii::warning('isInteractiveMessageReply ' . intval($answer->isInteractiveMessageReply()) . ' answer' . $answer->getValue() . ' ' . $answer->getText() . ' ' . $answer->getCallbackId());
         if ($answer->isInteractiveMessageReply()) {
            \Yii::warning('getValue ' . $selectedValue);
               return $this->showItemsListFacebookType($items, $counter);
         }
      });


      return $question;
   }

If I use same function with simple buttons, wirhout Generic template, it working great:

   /**
    * @param $items
    * @param $first
    * @return object
    * @throws \Exception
    */
   public function showItemsListFacebookTypeButtons($items, $first = 0) //TODO: to 1 variant
   {
      if ($first > 0) \Yii::warning('Цикличный Вызов пошел');
      if (!count($items)) {
         $this->say('Events is not found!');
         $this->showCommands();
      }

      $allCount = count($items);
      $counter = 0;
      $buttons = [];
      foreach ($items as $item) {
         $counter++;
         if ($first > 0) \Yii::warning($counter);
         if ($counter < $first) continue;
         if (($counter - $first) == 10) {
            break;
         }

         $date = new \DateTime($item->datetime);
         $timeString = $date->Format('h:i');
         if (in_array($timeString, ['03:30', '03:30'])) $timeString = 'TBA';
         $state = $item->state ? $item->state->abbreviation : '';
         $abbreviation = $item->state->abbreviation ? ', ' . $item->state->abbreviation : '';
         $cityAndState = $item->city->name . $abbreviation;

         $buttons[] = Button::create($item->name)->value($item->id);
         if (($counter - $first) == 9 && $allCount > $counter) {
            $buttons[] = Button::create('Show more variants!')->value('Show more variants!');
         }
      }

      $question = Question::create('Test Buttons Items')->addButtons($buttons)
         ->fallback('Don\'t understand')
         ->callbackId('choose_city');

      \Yii::warning('Counter ' . $counter . ' allCount ' . $allCount);
      $this->ask($question, function (Answer $answer) use ($items, $counter) {
         $selectedValue = $answer->getValue();
         \Yii::warning('isInteractiveMessageReply ' . intval($answer->isInteractiveMessageReply()) . ' answer' . $answer->getValue() . ' ' . $answer->getText() . ' ' . $answer->getCallbackId());
         if ($answer->isInteractiveMessageReply()) {
            \Yii::warning('getTExt ' . $selectedValue);
               return $this->showItemsListFacebookTypeButtons($items, $counter);
         }
      });


      return $question;
   }
@IljaPHP IljaPHP changed the title Facebook Generic template. Code inside the $this->ask method is not working. (( Facebook Generic template. Code inside the $this->ask method is not working. I guess, problem on the Botman side!!! Sep 29, 2020
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

1 participant