Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Commitc6e3f9b
committed
feature#61778 [Notifier] Add support for building SmsEvent by dlr_code and RemoteEvent for other LOX24 webhook event types (alebedev80)
This PR was squashed before being merged into the 7.4 branch.Discussion----------[Notifier] Add support for building SmsEvent by dlr_code and RemoteEvent for other LOX24 webhook event types| Q | A| ------------- | ---| Branch? | 7.4| Bug fix? | yes| New feature? | yes| Deprecations? | no| Issues | Fix #... (if applicable)| License | MIT## SummaryThis PR enhances the LOX24RequestParser to provide robust SMS delivery webhook parsing with improved validation, dual status code support (DLR codes and status codes), and better error handling for SMS delivery events.## What it does**Before**: The parser had basic SMS delivery webhook handling with limited validation and error handling.**After**: The parser provides enhanced SMS delivery webhook processing:- `sms.delivery` & `sms.delivery.dryrun` - SMS delivery receipts with improved validation- Dual status code support: DLR codes (0-16) and transmission status codes (0, 100, etc.)- Better payload validation with detailed error messages- Non-delivery events are handled as generic RemoteEvent objects## Example Usage### Enhanced SMS Delivery Processing:```php// ✅ SMS delivery with status code$deliveryPayload = [ 'id' => 'webhook-123', 'name' => 'sms.delivery', 'data' => ['id' => '123', 'status_code' => 100]];$deliveryEvent = $parser->parse($deliveryRequest, $secret);// Returns: SmsEvent with DELIVERED status// ✅ SMS delivery with DLR code (takes priority over status_code)$dlrPayload = [ 'id' => 'webhook-456', 'name' => 'sms.delivery', 'data' => ['id' => '456', 'dlr_code' => 1, 'status_code' => 500]];$dlrEvent = $parser->parse($dlrRequest, $secret);// Returns: SmsEvent with DELIVERED status (DLR code 1 overrides status 500)// ✅ Pending delivery (returns null)$pendingPayload = [ 'id' => 'webhook-789', 'name' => 'sms.delivery', 'data' => ['id' => '789', 'dlr_code' => 0]];$pendingEvent = $parser->parse($pendingRequest, $secret);// Returns: null (pending delivery)// ✅ Non-delivery events handled as RemoteEvent$otherPayload = [ 'id' => 'webhook-000', 'name' => 'custom.event', 'data' => ['some' => 'data']];$otherEvent = $parser->parse($otherRequest, $secret);// Returns: RemoteEvent with 'custom.event' name```## Key Changes### 1. **Improved Payload Validation**- Enhanced validation for required webhook fields: `id`, `name`, `data`- Better error messages with specific missing field details- Proper array validation for data payload### 2. **Smart Return Types**- SMS delivery events (`sms.delivery`, `sms.delivery.dryrun`) return `SmsEvent` objects with DELIVERED/FAILED status- Non-delivery events return `RemoteEvent` objects for generic webhook handling- Maintains `null` return for pending deliveries (status_code=0 or dlr_code=0/2/4)### 3. **Enhanced SMS Delivery Validation**```php// SMS delivery events validate required fieldscase 'sms.delivery': // Requires: payload.id, data.id, and either data.status_code OR data.dlr_code // Supports both LOX24 status codes and DLR codes // DLR codes take priority when both are present```### 4. **Dual Status Code Support**- **DLR Codes**: Priority support for LOX24's Delivery Report codes (0-16) with proper pending state handling- **Status Codes**: Fallback to transmission status codes (0, 100, 208, 400, etc.) when DLR unavailable- **Smart Mapping**: DLR codes 1→DELIVERED, 8/16→FAILED, 0/2/4→null (pending)### 4. **Comprehensive Testing**- Tests for SMS delivery events with success/failure scenarios- DLR code and status code validation scenarios- Payload validation tests for required fields- Backward compatibility verification for existing delivery events- Type safety assertions (`SmsEvent` vs `RemoteEvent`)## Backward Compatibility✅ **Fully backward compatible** - existing consumers continue working without changes:- Same `sms.delivery` event handling behavior- Same status code and DLR code mapping logic- Same null return for pending messages (status_code=0, dlr_code=0/2/4)- Same SmsEvent object structure and methods- Enhanced support for both LOX24 status codes and DLR codes## Consumer Integration Example```php#[AsRemoteEventConsumer('lox24_notifier')]class LOX24WebhookConsumer implements ConsumerInterface{ public function consume(RemoteEvent $event): void { if ($event instanceof SmsEvent) { match($event->getName()) { SmsEvent::DELIVERED => $this->handleDelivered($event), SmsEvent::FAILED => $this->handleFailed($event), }; } else { // Handle other webhook events as generic RemoteEvent $this->handleGenericWebhook($event); } }}```## Breaking ChangesFile tree
3 files changed
+312
-34
lines changed- src/Symfony/Component/Notifier/Bridge/Lox24
- Tests/Webhook
- Webhook
3 files changed
+312
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
7 | | - | |
| 12 | + | |
Lines changed: 228 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
50 | | - | |
| 55 | + | |
51 | 56 | | |
52 | 57 | | |
53 | | - | |
54 | | - | |
| 58 | + | |
55 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
56 | 65 | | |
57 | 66 | | |
58 | 67 | | |
59 | | - | |
| 68 | + | |
60 | 69 | | |
61 | 70 | | |
| 71 | + | |
62 | 72 | | |
63 | 73 | | |
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
67 | 77 | | |
68 | | - | |
69 | 78 | | |
| 79 | + | |
70 | 80 | | |
| 81 | + | |
| 82 | + | |
71 | 83 | | |
72 | 84 | | |
73 | 85 | | |
74 | 86 | | |
75 | 87 | | |
76 | | - | |
| 88 | + | |
77 | 89 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
87 | 98 | | |
88 | 99 | | |
89 | 100 | | |
90 | 101 | | |
91 | 102 | | |
92 | | - | |
| 103 | + | |
93 | 104 | | |
94 | 105 | | |
| 106 | + | |
95 | 107 | | |
96 | 108 | | |
97 | 109 | | |
98 | | - | |
| 110 | + | |
| 111 | + | |
99 | 112 | | |
100 | 113 | | |
| 114 | + | |
101 | 115 | | |
| 116 | + | |
102 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
103 | 136 | | |
| 137 | + | |
| 138 | + | |
104 | 139 | | |
105 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
106 | 311 | | |
107 | 312 | | |
108 | 313 | | |
| |||
0 commit comments
Comments
(0)