-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFBButton.php
109 lines (102 loc) · 2.3 KB
/
FBButton.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* See: https://developers.facebook.com/docs/messenger-platform/send-api-reference/buttons
*/
class FBButton {
public $type;
public function __construct() {
return $this;
}
}
class FBButtonUrl extends FBButton {
public $url;
public $title;
public $webview_height_ratio;
public $webview_share_button;
public function __construct() {
$this->type = 'web_url';
return $this;
}
public function setUrl($url) {
$this->url = $url;
return $this;
}
public function setTitle($title) {
// 20 character limit
$this->title = $title;
return $this;
}
public function setWebviewHeightRatio($webview_height_ratio) {
// must be compact, tall, or full
$this->webview_height_ratio = $webview_height_ratio;
return $this;
}
public function setWebviewShareButtonHidden() {
$this->webview_share_button = 'hide';
return $this;
}
}
class FBButtonUrlWithExtensions extends FBButtonUrl {
public $messenger_extensions;
public $fallback_url;
public function __construct() {
$this->type = 'web_url';
$this->messenger_extensions = true;
return $this;
}
public function setUrl($url) {
$this->url = $url;
$this->fallback_url = $url;
return $this;
}
public function setFallbackUrl($fallback_url) {
$this->fallback_url = $fallback_url;
return $this;
}
}
class FBButtonPostback extends FBButton {
public $title;
public $payload;
public function __construct() {
$this->type = 'postback';
return $this;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function setPayload($payload) {
$this->payload = $payload;
return $this;
}
}
class FBButtonShare extends FBButton {
public function __construct() {
$this->type = 'element_share';
return $this;
}
}
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/buy-button
class FBButtonBuy extends FBButton {
public $title;
public $payload;
public $payment_summary;
public function __construct() {
$this->type = 'payment';
$this->title = 'buy'; // required
return $this;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function setPayload($payload) {
$this->payload = $payload;
return $this;
}
public function setPaymentSummary($payment_summary) {
// TBD
$this->payment_summary = $payment_summary;
return $this;
}
}