Commit 98c8815
authored
Automate parse webhook (#677)
Resolve #673
## Summary
When a new webhook type is added, we had to update manually
(#664,
#556).
I've created a function to parse the class that uses polymorphism and
fixed it. it prevents human errors in release new Webhook.
## Breaking changes
This PR has some breaking changes to parse Webhook events automatically
### joined.members and left.members will be serialized into the
UserSource classes.
The joined.members and left.members were associative arrays, but now
they are correctly serialized into the UserSource class.
```diff
...
["members"]=>
array(1) {
[0]=>
- array(2) {
- ["type"]=>
- string(4) "user"
- ["userId"]=>
- string(14) "U4af4980629..."
- }
+ object(LINE\Webhook\Model\UserSource)#256 (2) {
+ ["openAPINullablesSetToNull":protected]=>
+ array(0) {
+ }
+ ["container":protected]=>
+ array(2) {
+ ["type"]=>
+ string(4) "user"
+ ["userId"]=>
+ string(14) "U4af4980629..."
+ }
+ }
...
```
Until now, the elements of members were mistakenly treated as
associative arrays, so we couldn't utilize the methods of UserSource.
With this implementation, the following can now be achieved.
```diff
$parsedEvents = EventRequestParser::parseEventRequest($req->getBody(), $secret, $req->getHeader(HTTPHeader::LINE_SIGNATURE)[0]);
foreach ($parsedEvents->getEvents() as $event) {
$joinedMembers = $event->getJoined()->getMembers();
$joinedMemberIds = array_map(function ($member) {
- return $member["userId"];
+ return $member->getUserId();
}, $joinedMembers);
}
```
### Default values will be unified to `NULL`.
The default values of array fields were not consistently set to empty
arrays (such as `message.emojis`) or `NULL` (such as `message.
keywords`). Fields with keys that do not exist in the sent webhook event
will have default values unified to `NULL`. For example, if the webhook
does not contain emojis in a text message event, the emoji in
ParsedEvent will change from an empty array to `NULL`.
```diff
...
["message"]=>
object(LINE\Webhook\Model\TextMessageContent)#166 (2) {
["openAPINullablesSetToNull":protected]=>
array(0) {
}
["container":protected]=>
array(7) {
["type"]=>
string(4) "text"
["id"]=>
string(9) "contentid"
["text"]=>
string(21) "message without emoji"
["emojis"]=>
- array(0) {
- }
+ NULL
["mention"]=>
NULL
["quoteToken"]=>
NULL
["quotedMessageId"]=>
NULL
}
}
...
```1 parent e98690a commit 98c8815
File tree
276 files changed
+9299
-955
lines changed- docs
- classes
- js
- examples/KitchenSink/src/LINEBot/KitchenSink
- EventHandler
- src
- clients
- channel-access-token/lib
- Model
- insight/lib
- Model
- liff/lib
- Model
- manage-audience/lib
- Model
- messaging-api/lib
- Model
- parser
- lib
- test
- webhook/lib/Model
- tools
- custom-template
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
276 files changed
+9299
-955
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
910 | | - | |
| 910 | + | |
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
910 | | - | |
| 910 | + | |
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
910 | | - | |
| 910 | + | |
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
910 | | - | |
| 910 | + | |
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
910 | | - | |
| 910 | + | |
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
| |||
Large diffs are not rendered by default.
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| |||
1122 | 1122 | | |
1123 | 1123 | | |
1124 | 1124 | | |
1125 | | - | |
| 1125 | + | |
1126 | 1126 | | |
1127 | 1127 | | |
1128 | 1128 | | |
| |||
1215 | 1215 | | |
1216 | 1216 | | |
1217 | 1217 | | |
1218 | | - | |
| 1218 | + | |
1219 | 1219 | | |
1220 | 1220 | | |
1221 | 1221 | | |
| |||
1285 | 1285 | | |
1286 | 1286 | | |
1287 | 1287 | | |
1288 | | - | |
| 1288 | + | |
1289 | 1289 | | |
1290 | 1290 | | |
1291 | 1291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40783 | 40783 | | |
40784 | 40784 | | |
40785 | 40785 | | |
40786 | | - | |
| 40786 | + | |
40787 | 40787 | | |
40788 | | - | |
40789 | | - | |
40790 | | - | |
40791 | | - | |
40792 | | - | |
40793 | | - | |
40794 | | - | |
40795 | | - | |
40796 | | - | |
40797 | | - | |
40798 | | - | |
40799 | | - | |
40800 | | - | |
40801 | | - | |
40802 | | - | |
40803 | | - | |
40804 | | - | |
40805 | | - | |
40806 | | - | |
40807 | | - | |
40808 | | - | |
40809 | | - | |
40810 | | - | |
40811 | | - | |
40812 | | - | |
40813 | | - | |
40814 | | - | |
40815 | | - | |
40816 | | - | |
40817 | | - | |
40818 | | - | |
40819 | | - | |
40820 | | - | |
40821 | | - | |
40822 | | - | |
40823 | | - | |
40824 | | - | |
40825 | | - | |
40826 | | - | |
40827 | | - | |
40828 | | - | |
40829 | | - | |
40830 | | - | |
40831 | | - | |
40832 | | - | |
40833 | | - | |
40834 | | - | |
40835 | | - | |
40836 | | - | |
40837 | | - | |
40838 | | - | |
40839 | | - | |
40840 | | - | |
40841 | | - | |
40842 | | - | |
40843 | | - | |
40844 | | - | |
40845 | | - | |
40846 | | - | |
40847 | | - | |
40848 | | - | |
40849 | | - | |
40850 | | - | |
40851 | | - | |
40852 | | - | |
40853 | 40788 | | |
40854 | 40789 | | |
40855 | 40790 | | |
| |||
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | | - | |
| 40 | + | |
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
| |||
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | | - | |
| 70 | + | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
0 commit comments