Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Add the List Template message plugin #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/Message/ListMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* @file
* Contains Drupal\fb_messenger_bot\Message\ListMessage.
*/

namespace Drupal\fb_messenger_bot\Message;

/**
* Class ListMessage.
*
* @package Drupal\fb_messenger_bot
*/
class ListMessage implements MessageInterface {

/**
* A nested array of list elements.
*/
protected $listElements;

/**
* ListMessage constructor.
*
* @param string $listElements
* The elements array.
*
* @throws \InvalidArgumentException
* Thrown if the $buttons argument contains invalid objects.
*
* @todo: Add verification that the URL is actually an image.
*/
public function __construct($listElements) {
if (is_array($listElements)) {
$this->listElements = $listElements;
}
else {
throw new \InvalidArgumentException("Invalid elements array.");
}
}

/**
* {@inheritdoc}
*/
public function getFormattedMessage() {
return [
'attachment' => [
'type' => 'template',
'payload' => [
'template_type' => 'list',
'elements' => $this->listElements,
],
],
];
}

}