-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for interactive messages (#341)
* Adding support for interactive messages
- Loading branch information
1 parent
bfeba2f
commit 34e3273
Showing
4 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace Plivo\Util; | ||
|
||
// Header class | ||
class Header { | ||
public $type; | ||
public $text; | ||
public $media; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->type = $data['type'] ?? null; | ||
$this->text = $data['text'] ?? null; | ||
$this->media = $data['media'] ?? null; | ||
} | ||
} | ||
|
||
// Body class | ||
class Body { | ||
public $text; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->text = $data['text'] ?? null; | ||
} | ||
} | ||
|
||
// Footer class | ||
class Footer { | ||
public $text; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->text = $data['text'] ?? null; | ||
} | ||
} | ||
|
||
// Buttons class | ||
class Buttons { | ||
public $id; | ||
public $title; | ||
public $cta_url; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->id = $data['id'] ?? null; | ||
$this->title = $data['title'] ?? null; | ||
$this->cta_url = $data['cta_url'] ?? null; | ||
} | ||
} | ||
|
||
// Row class | ||
class Row { | ||
public $id; | ||
public $title; | ||
public $description; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->id = $data['id'] ?? null; | ||
$this->title = $data['title'] ?? null; | ||
$this->description = $data['description'] ?? null; | ||
} | ||
} | ||
|
||
// Section class | ||
class Section { | ||
public $title; | ||
public $rows; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->title = $data['title'] ?? null; | ||
$this->rows = array_map(function($row) { return new Row($row); }, $data['rows'] ?? []); | ||
} | ||
} | ||
|
||
// Action class | ||
class Action { | ||
public $buttons; | ||
public $sections; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->buttons = array_map(function($btn) { return new Buttons($btn); }, $data['buttons'] ?? []); | ||
$this->sections = array_map(function($section) { return new Section($section); }, $data['sections'] ?? []); | ||
} | ||
} | ||
|
||
// Interactive class | ||
class Interactive { | ||
public $type; | ||
public $header; | ||
public $body; | ||
public $footer; | ||
public $action; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->type = $data['type'] ?? null; | ||
$this->header = new Header($data['header'] ?? []); | ||
$this->body = new Body($data['body'] ?? []); | ||
$this->footer = new Footer($data['footer'] ?? []); | ||
$this->action = new Action($data['action'] ?? []); | ||
} | ||
|
||
public function validateInteractive(string $interactive) | ||
{ | ||
// Additional validation logic can be implemented here if needed | ||
if(is_null(json_decode($interactive, true))) { | ||
return "Invalid JSON data for interactive messages!"; | ||
} | ||
//Instantiate and validate the Interactive class | ||
$interactive = new Interactive(json_decode($interactive, true)); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters