-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatMessage.php
144 lines (131 loc) · 4.27 KB
/
formatMessage.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
// all method is for example only, you can modify it as you want.
// quoted is optional, default is false,, quoted = reply to specific message
class FormatMessage
{
public static function text($text, $quoted = false)
{
return json_encode(['text' => $text, 'quoted' => $quoted]);
}
public static function exampleMedia($quoted = false)
{
// image
// ['image' => ['url' => 'url_image'], 'caption' => 'text', 'quoted' => true or false]
// video
// ['video' => ['url' => 'url_video'], 'caption' => 'text', 'quoted' => true or false]
// audio
// ['audio' => ['url' => 'url_audio'], 'ptt' => true or false, 'quoted' => true or false, 'fileName' => 'filename.mp3', 'mimetype' => 'audio/mpeg']
// pdf
// ['document' => ['url' => 'url_pdf'], 'quoted' => true or false, 'fileName' => 'filename.pdf', 'mimetype' => 'application/pdf']
return json_encode([
'image' => [
'url' =>
'https://png.pngtree.com/element_our/md/20180626/md_5b321c99945a2.jpg',
],
'caption' => 'caption',
'quoted' => $quoted,
]);
}
public static function exampleButton($quoted = false)
{
// button
$buttons = [
[
'buttonId' => 'id1',
'buttonText' => ['displayText' => 'Button 1'],
'type' => 1,
],
[
'buttonId' => 'id2',
'buttonText' => ['displayText' => 'Button 2'],
'type' => 1,
],
[
'buttonId' => 'id3',
'buttonText' => ['displayText' => 'Button 3'],
'type' => 1,
],
];
$message = [
'text' => 'text',
'footer' => 'footer',
'headerType' => 1,
'buttons' => $buttons,
'quoted' => $quoted,
];
// if wnat to add image you can add like this to $message
// $message['image'] = ['url' => 'url_image']; and change text to caption
return json_encode($message);
}
public static function exampleTemplate($quoted = false)
{
$templateButtons = [
[
'index' => 1,
'urlButton' => [
'displayText' => 'Visit our website',
'url' => 'https://www.quilchat.com',
],
],
[
'index' => 2,
'callButton' => [
'displayText' => 'Call us now',
'phoneNumber' => '+1234567890',
],
],
];
$message = [
'text' => 'text',
'footer' => 'footer', // optional
'templateButtons' => $templateButtons,
'viewOnce' => true,
'quoted' => $quoted, // optional
];
// if wnat to add image you can add like this to $message
// $message['image'] = ['url' => 'url_image']; and change text to caption
return json_encode($message);
}
public static function exampleList($quoted = false)
{
$section = [
'title' => 'Menu List',
'rows' => [
[
'title' => 'List Item 1',
'rowId' => 'id2',
'description' => '',
],
[
'title' => 'List Item 2',
'rowId' => 'id3',
'description' => '',
],
],
];
$section2 = [
'title' => 'Menu List 2',
'rows' => [
[
'title' => 'List Item 1',
'rowId' => 'id2',
'description' => '',
],
[
'title' => 'List Item 2',
'rowId' => 'id3',
'description' => '',
],
],
];
$listMessage = [
'text' => 'text',
'footer' => 'footer',
'title' => 'name of list',
'buttonText' => 'button of list',
'sections' => [$section, $section2],
];
return json_encode($listMessage);
}
}
?>