Skip to content

Types & Events#

flet_onesignal.types #

Types, enums, and dataclasses for flet-onesignal.

This module defines all event types, enums, and data structures used throughout the flet-onesignal SDK.

Classes#

OSErrorEvent dataclass #

Event fired when an error occurs in the SDK.

Example
def on_error(e: fos.OSErrorEvent):
    print(f"Error in {e.method}: {e.message}")
Attributes#
message class-attribute instance-attribute #
message: Optional[str] = None

The error message.

method class-attribute instance-attribute #
method: Optional[str] = None

The SDK method that caused the error.

stack_trace class-attribute instance-attribute #
stack_trace: Optional[str] = None

The stack trace, if available.

OSInAppMessageClickEvent dataclass #

Event fired when a user clicks on an in-app message.

Example
def on_iam_click(e: fos.OSInAppMessageClickEvent):
    print(f"Action: {e.result.action_id}")
    print(f"URL: {e.result.url}")
Attributes#
action_id class-attribute instance-attribute #
action_id: Optional[str] = None

The action ID defined in the OneSignal dashboard.

closing_message class-attribute instance-attribute #
closing_message: bool = False

True if the click action closes the in-app message.

message class-attribute instance-attribute #
message: dict = None

The in-app message payload.

result property #
result: OSInAppMessageClickResult

Get the click result as an OSInAppMessageClickResult object.

url class-attribute instance-attribute #
url: Optional[str] = None

The URL associated with the click action, if any.

url_target class-attribute instance-attribute #
url_target: Optional[str] = None

The URL target (_blank, _self, etc.).

OSInAppMessageClickResult dataclass #

Result of an in-app message click action.

Attributes#
action_id class-attribute instance-attribute #
action_id: Optional[str] = None

The action ID defined in the OneSignal dashboard.

closing_message class-attribute instance-attribute #
closing_message: bool = False

True if the click action closes the in-app message.

url class-attribute instance-attribute #
url: Optional[str] = None

The URL associated with the click action, if any.

url_target class-attribute instance-attribute #
url_target: Optional[str] = None

The URL target (_blank, _self, etc.).

OSInAppMessageDidDismissEvent dataclass #

Event fired after an in-app message is dismissed.

Attributes#
message class-attribute instance-attribute #
message: dict = None

The in-app message payload.

OSInAppMessageDidDisplayEvent dataclass #

Event fired after an in-app message is displayed.

Attributes#
message class-attribute instance-attribute #
message: dict = None

The in-app message payload.

OSInAppMessageWillDismissEvent dataclass #

Event fired before an in-app message is dismissed.

Attributes#
message class-attribute instance-attribute #
message: dict = None

The in-app message payload.

OSInAppMessageWillDisplayEvent dataclass #

Event fired before an in-app message is displayed.

Attributes#
message class-attribute instance-attribute #
message: dict = None

The in-app message payload.

OSLogLevel #

OneSignal SDK log levels.

Controls the verbosity of SDK console/logcat output.

Example
onesignal = fos.OneSignal(
    app_id="your-app-id",
    log_level=fos.OSLogLevel.DEBUG,
)
Attributes#
DEBUG class-attribute instance-attribute #
DEBUG = 'debug'

Debug messages and above.

ERROR class-attribute instance-attribute #
ERROR = 'error'

Errors and fatal errors.

FATAL class-attribute instance-attribute #
FATAL = 'fatal'

Only fatal errors.

INFO class-attribute instance-attribute #
INFO = 'info'

Informational messages and above.

NONE class-attribute instance-attribute #
NONE = 'none'

No logging.

VERBOSE class-attribute instance-attribute #
VERBOSE = 'verbose'

All messages including verbose details.

WARN class-attribute instance-attribute #
WARN = 'warn'

Warnings and above.

OSNotificationClickEvent dataclass #

Event fired when a user clicks on a notification.

Example
def on_click(e: fos.OSNotificationClickEvent):
    print(f"Clicked: {e.notification}")
    print(f"Action: {e.action_id}")

onesignal = fos.OneSignal(
    app_id="...",
    on_notification_click=on_click,
)
Attributes#
action_id class-attribute instance-attribute #
action_id: Optional[str] = None

The action button ID if the user tapped an action button, or None.

notification instance-attribute #
notification: dict

The notification payload as a dictionary.

OSNotificationWillDisplayEvent dataclass #

Event fired when a notification is about to be displayed in foreground.

Use this to intercept and optionally suppress notification display when the app is in the foreground.

Example
async def on_foreground(e: fos.OSNotificationWillDisplayEvent):
    # Suppress display
    await onesignal.notifications.prevent_default(e.notification_id)

onesignal = fos.OneSignal(
    app_id="...",
    on_notification_foreground=on_foreground,
)
Attributes#
notification instance-attribute #
notification: dict

The notification payload as a dictionary.

notification_id class-attribute instance-attribute #
notification_id: Optional[str] = None

The notification ID, used with prevent_default() and display().

OSPermissionChangeEvent dataclass #

Event fired when notification permission status changes.

Attributes#
permission class-attribute instance-attribute #
permission: bool = False

True if notifications are now permitted, False otherwise.

OSPushSubscriptionChangedEvent dataclass #

Event fired when push subscription state changes.

Attributes#
id class-attribute instance-attribute #
id: Optional[str] = None

The push subscription ID.

opted_in class-attribute instance-attribute #
opted_in: bool = False

True if the user is opted in to push notifications.

token class-attribute instance-attribute #
token: Optional[str] = None

The push token (FCM/APNs).

OSUserChangedEvent dataclass #

Event fired when the user state changes.

Attributes#
external_id class-attribute instance-attribute #
external_id: Optional[str] = None

The external user ID set via login().

onesignal_id class-attribute instance-attribute #
onesignal_id: Optional[str] = None

The OneSignal-generated user ID.

state property #
state: OSUserState

Get the user state as an OSUserState object.

OSUserState dataclass #

Represents the current OneSignal user state.

Attributes#
external_id class-attribute instance-attribute #
external_id: Optional[str] = None

The external user ID set via login().

onesignal_id class-attribute instance-attribute #
onesignal_id: Optional[str] = None

The OneSignal-generated user ID.