WebhookEvent class abstract final

An event delivered to a webhook or route URL.

Use WebhookVerifier.verify to check the signature and parse the body in one step. To parse a body that was verified elsewhere, use WebhookEvent.parse or WebhookEvent.fromJson.

Switch over the subclasses to handle the events you care about, and keep a default branch. AhaSend can add event types at any time: a type this version of the package does not know arrives as an UnknownWebhookEvent, and a later version may decode it into a new subclass. Neither breaks your code. To handle a type the package does not know yet, match on type rather than on UnknownWebhookEvent, so the code keeps working once the package learns it.

switch (event) {
  case MessageDeliveredEvent(:final data):
    print('Delivered to ${data.recipient}');
  case MessageBouncedEvent(:final data):
    print('Bounced: ${data.deliveryAttempt?.classification}');
  case MessageRoutingEvent(:final data):
    print('Inbound from ${data.from}: ${data.subject}');
  default:
    break;
}
Implementers

Constructors

WebhookEvent.fromJson(JsonMap json)
Decodes an event from its JSON payload, without verifying it.
factory
WebhookEvent.parse(String body)
Decodes an event from a JSON request body, without verifying it.
factory

Properties

data → Object?
The event-specific data.
no setter
hashCode → int
The hash code for this object.
no setterinherited
raw → JsonMap
The JSON payload this event was decoded from.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
timestamp → DateTime
When the event occurred.
final
type → String
The event type, for example message.delivered.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() → JsonMap
Encodes this event as JSON.
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited