001// Generated by delombok at Thu Aug 13 13:56:44 UTC 2026 002/* 003 * Copyright (c) 2010-2026 Mark Allen, Norbert Bartels. 004 * 005 * Permission is hereby granted, free of charge, to any person obtaining a copy 006 * of this software and associated documentation files (the "Software"), to deal 007 * in the Software without restriction, including without limitation the rights 008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 009 * copies of the Software, and to permit persons to whom the Software is 010 * furnished to do so, subject to the following conditions: 011 * 012 * The above copyright notice and this permission notice shall be included in 013 * all copies or substantial portions of the Software. 014 * 015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 021 * THE SOFTWARE. 022 */ 023package com.restfb.types.webhook.messaging; 024 025import java.util.ArrayList; 026import java.util.Date; 027import java.util.List; 028import com.restfb.Facebook; 029import com.restfb.JsonMapper; 030import com.restfb.json.JsonObject; 031import com.restfb.json.JsonValue; 032 033public class MessagingItem { 034 @Facebook 035 private MessagingParticipant sender; 036 @Facebook 037 private MessagingParticipant recipient; 038 @Facebook("timestamp") 039 private Long rawTimestamp; 040 private Date timestamp; 041 @Facebook 042 private DeliveryItem delivery; 043 @Facebook 044 private ReadItem read; 045 @Facebook 046 private MessageItem message; 047 @Facebook("message_edit") 048 private MessageEditItem messageEdit; 049 @Facebook 050 private PostbackItem postback; 051 @Facebook 052 private OptinItem optin; 053 @Facebook("account_linking") 054 private AccountLinkingItem accountLinking; 055 @Facebook("checkout_update") 056 private CheckoutUpdateItem checkoutUpdate; 057 @Facebook 058 private PaymentItem payment; 059 @Facebook 060 private ReferralItem referral; 061 @Facebook("policy-enforcement") 062 private PolicyEnforcementItem policyEnforcement; 063 @Facebook("pass_thread_control") 064 private PassThreadControlItem passThreadControl; 065 @Facebook("take_thread_control") 066 private TakeThreadControlItem takeThreadControl; 067 @Facebook("request_thread_control") 068 private RequestThreadControlItem requestThreadControl; 069 private AppRoles appRoles; 070 @Facebook("prior_message") 071 private PriorMessage priorMessage; 072 @Facebook 073 private MessageReaction reaction; 074 @Facebook("app_roles") 075 private JsonObject rawAppRoles; 076 077 /** 078 * generic access to the inner item. 079 * 080 * depending on the inner elements the corresponding element is returned. So you can get an {@link OptinItem}, 081 * {@link PostbackItem}, {@link DeliveryItem}, {@link AccountLinkingItem} or {@link MessageItem} 082 * 083 * @return the inner item. 084 */ 085 public InnerMessagingItem getItem() { 086 if (optin != null) { 087 return optin; 088 } 089 if (postback != null) { 090 return postback; 091 } 092 if (delivery != null) { 093 return delivery; 094 } 095 if (read != null) { 096 return read; 097 } 098 if (accountLinking != null) { 099 return accountLinking; 100 } 101 if (message != null) { 102 return message; 103 } 104 if (checkoutUpdate != null) { 105 return checkoutUpdate; 106 } 107 if (payment != null) { 108 return payment; 109 } 110 if (referral != null) { 111 return referral; 112 } 113 if (policyEnforcement != null) { 114 return policyEnforcement; 115 } 116 if (passThreadControl != null) { 117 return passThreadControl; 118 } 119 if (takeThreadControl != null) { 120 return takeThreadControl; 121 } 122 if (requestThreadControl != null) { 123 return requestThreadControl; 124 } 125 if (appRoles != null) { 126 return appRoles; 127 } 128 if (reaction != null) { 129 return reaction; 130 } 131 return null; 132 } 133 134 public boolean isDelivery() { 135 return getItem() instanceof DeliveryItem; 136 } 137 138 public boolean isRead() { 139 return getItem() instanceof ReadItem; 140 } 141 142 public boolean isMessage() { 143 return getItem() instanceof MessageItem; 144 } 145 146 public boolean isPostback() { 147 return getItem() instanceof PostbackItem; 148 } 149 150 public boolean isOptin() { 151 return getItem() instanceof OptinItem; 152 } 153 154 public boolean isAccountLinking() { 155 return getItem() instanceof AccountLinkingItem; 156 } 157 158 public boolean isCheckoutUpdate() { 159 return getItem() instanceof CheckoutUpdateItem; 160 } 161 162 public boolean isPayment() { 163 return getItem() instanceof PaymentItem; 164 } 165 166 public boolean isReferral() { 167 return getItem() instanceof ReferralItem; 168 } 169 170 public boolean isPolicyEnforcement() { 171 return getItem() instanceof PolicyEnforcementItem; 172 } 173 174 public boolean isPassThreadControl() { 175 return getItem() instanceof PassThreadControlItem; 176 } 177 178 public boolean isTakeThreadControl() { 179 return getItem() instanceof TakeThreadControlItem; 180 } 181 182 public boolean isRequestThreadControl() { 183 return getItem() instanceof RequestThreadControlItem; 184 } 185 186 public boolean isAppRoles() { 187 return getItem() instanceof AppRoles; 188 } 189 190 public boolean hasPriorMessage() { 191 return priorMessage != null; 192 } 193 194 public boolean isReaction() { 195 return getItem() instanceof MessageReaction; 196 } 197 198 @JsonMapper.JsonMappingCompleted 199 private void convertDate() { 200 if (rawTimestamp != null) { 201 timestamp = new Date(rawTimestamp); 202 } 203 } 204 205 @JsonMapper.JsonMappingCompleted 206 private void convertAppRoles() { 207 if (rawAppRoles != null) { 208 AppRoles appRoles = new AppRoles(); 209 for (String appId : rawAppRoles.names()) { 210 List<JsonValue> rawRoles = rawAppRoles.get(appId).asArray().values(); 211 List<String> roles = new ArrayList<>(); 212 for (JsonValue rawValue : rawRoles) { 213 roles.add(rawValue.asString()); 214 } 215 appRoles.addRoles(appId, roles); 216 } 217 this.appRoles = appRoles; 218 } 219 } 220 221 @java.lang.Override 222 @java.lang.SuppressWarnings("all") 223 @lombok.Generated 224 public java.lang.String toString() { 225 return "MessagingItem(sender=" + this.getSender() + ", recipient=" + this.getRecipient() + ", rawTimestamp=" + this.rawTimestamp + ", timestamp=" + this.getTimestamp() + ", delivery=" + this.getDelivery() + ", read=" + this.getRead() + ", message=" + this.getMessage() + ", messageEdit=" + this.getMessageEdit() + ", postback=" + this.getPostback() + ", optin=" + this.getOptin() + ", accountLinking=" + this.getAccountLinking() + ", checkoutUpdate=" + this.getCheckoutUpdate() + ", payment=" + this.getPayment() + ", referral=" + this.getReferral() + ", policyEnforcement=" + this.getPolicyEnforcement() + ", passThreadControl=" + this.getPassThreadControl() + ", takeThreadControl=" + this.getTakeThreadControl() + ", requestThreadControl=" + this.getRequestThreadControl() + ", appRoles=" + this.getAppRoles() + ", priorMessage=" + this.getPriorMessage() + ", reaction=" + this.getReaction() + ", rawAppRoles=" + this.rawAppRoles + ")"; 226 } 227 228 @java.lang.SuppressWarnings("all") 229 @lombok.Generated 230 public MessagingParticipant getSender() { 231 return this.sender; 232 } 233 234 @java.lang.SuppressWarnings("all") 235 @lombok.Generated 236 public void setSender(final MessagingParticipant sender) { 237 this.sender = sender; 238 } 239 240 @java.lang.SuppressWarnings("all") 241 @lombok.Generated 242 public MessagingParticipant getRecipient() { 243 return this.recipient; 244 } 245 246 @java.lang.SuppressWarnings("all") 247 @lombok.Generated 248 public void setRecipient(final MessagingParticipant recipient) { 249 this.recipient = recipient; 250 } 251 252 @java.lang.SuppressWarnings("all") 253 @lombok.Generated 254 public Date getTimestamp() { 255 return this.timestamp; 256 } 257 258 @java.lang.SuppressWarnings("all") 259 @lombok.Generated 260 public void setTimestamp(final Date timestamp) { 261 this.timestamp = timestamp; 262 } 263 264 @java.lang.SuppressWarnings("all") 265 @lombok.Generated 266 public DeliveryItem getDelivery() { 267 return this.delivery; 268 } 269 270 @java.lang.SuppressWarnings("all") 271 @lombok.Generated 272 public void setDelivery(final DeliveryItem delivery) { 273 this.delivery = delivery; 274 } 275 276 @java.lang.SuppressWarnings("all") 277 @lombok.Generated 278 public ReadItem getRead() { 279 return this.read; 280 } 281 282 @java.lang.SuppressWarnings("all") 283 @lombok.Generated 284 public void setRead(final ReadItem read) { 285 this.read = read; 286 } 287 288 @java.lang.SuppressWarnings("all") 289 @lombok.Generated 290 public MessageItem getMessage() { 291 return this.message; 292 } 293 294 @java.lang.SuppressWarnings("all") 295 @lombok.Generated 296 public void setMessage(final MessageItem message) { 297 this.message = message; 298 } 299 300 @java.lang.SuppressWarnings("all") 301 @lombok.Generated 302 public MessageEditItem getMessageEdit() { 303 return this.messageEdit; 304 } 305 306 @java.lang.SuppressWarnings("all") 307 @lombok.Generated 308 public void setMessageEdit(final MessageEditItem messageEdit) { 309 this.messageEdit = messageEdit; 310 } 311 312 @java.lang.SuppressWarnings("all") 313 @lombok.Generated 314 public PostbackItem getPostback() { 315 return this.postback; 316 } 317 318 @java.lang.SuppressWarnings("all") 319 @lombok.Generated 320 public void setPostback(final PostbackItem postback) { 321 this.postback = postback; 322 } 323 324 @java.lang.SuppressWarnings("all") 325 @lombok.Generated 326 public OptinItem getOptin() { 327 return this.optin; 328 } 329 330 @java.lang.SuppressWarnings("all") 331 @lombok.Generated 332 public void setOptin(final OptinItem optin) { 333 this.optin = optin; 334 } 335 336 @java.lang.SuppressWarnings("all") 337 @lombok.Generated 338 public AccountLinkingItem getAccountLinking() { 339 return this.accountLinking; 340 } 341 342 @java.lang.SuppressWarnings("all") 343 @lombok.Generated 344 public void setAccountLinking(final AccountLinkingItem accountLinking) { 345 this.accountLinking = accountLinking; 346 } 347 348 @java.lang.SuppressWarnings("all") 349 @lombok.Generated 350 public CheckoutUpdateItem getCheckoutUpdate() { 351 return this.checkoutUpdate; 352 } 353 354 @java.lang.SuppressWarnings("all") 355 @lombok.Generated 356 public void setCheckoutUpdate(final CheckoutUpdateItem checkoutUpdate) { 357 this.checkoutUpdate = checkoutUpdate; 358 } 359 360 @java.lang.SuppressWarnings("all") 361 @lombok.Generated 362 public PaymentItem getPayment() { 363 return this.payment; 364 } 365 366 @java.lang.SuppressWarnings("all") 367 @lombok.Generated 368 public void setPayment(final PaymentItem payment) { 369 this.payment = payment; 370 } 371 372 @java.lang.SuppressWarnings("all") 373 @lombok.Generated 374 public ReferralItem getReferral() { 375 return this.referral; 376 } 377 378 @java.lang.SuppressWarnings("all") 379 @lombok.Generated 380 public void setReferral(final ReferralItem referral) { 381 this.referral = referral; 382 } 383 384 @java.lang.SuppressWarnings("all") 385 @lombok.Generated 386 public PolicyEnforcementItem getPolicyEnforcement() { 387 return this.policyEnforcement; 388 } 389 390 @java.lang.SuppressWarnings("all") 391 @lombok.Generated 392 public void setPolicyEnforcement(final PolicyEnforcementItem policyEnforcement) { 393 this.policyEnforcement = policyEnforcement; 394 } 395 396 @java.lang.SuppressWarnings("all") 397 @lombok.Generated 398 public PassThreadControlItem getPassThreadControl() { 399 return this.passThreadControl; 400 } 401 402 @java.lang.SuppressWarnings("all") 403 @lombok.Generated 404 public void setPassThreadControl(final PassThreadControlItem passThreadControl) { 405 this.passThreadControl = passThreadControl; 406 } 407 408 @java.lang.SuppressWarnings("all") 409 @lombok.Generated 410 public TakeThreadControlItem getTakeThreadControl() { 411 return this.takeThreadControl; 412 } 413 414 @java.lang.SuppressWarnings("all") 415 @lombok.Generated 416 public void setTakeThreadControl(final TakeThreadControlItem takeThreadControl) { 417 this.takeThreadControl = takeThreadControl; 418 } 419 420 @java.lang.SuppressWarnings("all") 421 @lombok.Generated 422 public RequestThreadControlItem getRequestThreadControl() { 423 return this.requestThreadControl; 424 } 425 426 @java.lang.SuppressWarnings("all") 427 @lombok.Generated 428 public void setRequestThreadControl(final RequestThreadControlItem requestThreadControl) { 429 this.requestThreadControl = requestThreadControl; 430 } 431 432 @java.lang.SuppressWarnings("all") 433 @lombok.Generated 434 public AppRoles getAppRoles() { 435 return this.appRoles; 436 } 437 438 @java.lang.SuppressWarnings("all") 439 @lombok.Generated 440 public void setAppRoles(final AppRoles appRoles) { 441 this.appRoles = appRoles; 442 } 443 444 @java.lang.SuppressWarnings("all") 445 @lombok.Generated 446 public PriorMessage getPriorMessage() { 447 return this.priorMessage; 448 } 449 450 @java.lang.SuppressWarnings("all") 451 @lombok.Generated 452 public void setPriorMessage(final PriorMessage priorMessage) { 453 this.priorMessage = priorMessage; 454 } 455 456 @java.lang.SuppressWarnings("all") 457 @lombok.Generated 458 public MessageReaction getReaction() { 459 return this.reaction; 460 } 461 462 @java.lang.SuppressWarnings("all") 463 @lombok.Generated 464 public void setReaction(final MessageReaction reaction) { 465 this.reaction = reaction; 466 } 467}