protected function getCommandListAttachment(Collection $handlers) : Attachment
 {
     $attachmentFields = $handlers->map(function (SignatureHandler $handler) {
         return AttachmentField::create($handler->getFullCommand(), $handler->getDescription());
     })->all();
     return Attachment::create()->setColor('warning')->setTitle('Did you mean:')->setFields($attachmentFields);
 }
Пример #2
0
 /**
  * Show a list of all available handlers.
  *
  * @param  Collection|SignatureHandler[] $handlers
  * @return Response
  */
 protected function displayListOfAllCommands(Collection $handlers) : Response
 {
     $attachmentFields = $handlers->sort(function (SignatureHandler $handlerA, SignatureHandler $handlerB) {
         return strcmp($handlerA->getFullCommand(), $handlerB->getFullCommand());
     })->map(function (SignatureHandler $handler) {
         return AttachmentField::create($handler->getFullCommand(), $handler->getDescription());
     })->all();
     return $this->respondToSlack('Available commands:')->withAttachment(Attachment::create()->setColor('good')->setFields($attachmentFields));
 }
 /**
  * Add a field to the attachment.
  *
  * @param \Spatie\SlashCommand\AttachmentField|array $field
  *
  * @return $this
  *
  * @throws \Spatie\SlashCommand\Exceptions\FieldCannotBeAdded
  */
 public function addField($field)
 {
     if (!is_array($field) && !$field instanceof AttachmentField) {
         throw FieldCannotBeAdded::invalidType();
     }
     if (is_array($field)) {
         $title = array_keys($field)[0];
         $value = $field[$title];
         $field = AttachmentField::create($title, $value);
     }
     $this->fields->push($field);
     return $this;
 }