// The treebars bridge an HTML in-app message calls, bridge version 3. // Generated from Treebars' bridge table; fetch it again rather than editing it. // Every method resolves, and never rejects: a refusal is { ok: false, reason }. export interface TreebarsBridge { /** Records `in_app_dismissed` (once per display) and closes the message. Closing this way IS counted, so a template need not record the dismissal itself first. Hosts: every host. */ dismissMessage(): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records `in_app_dismissed` with the element; does not close. A `dismissMessage()` after it does not count twice. Hosts: every host. */ trackDismiss(widgetId?: string | number): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records `in_app_clicked` with the element (a whole number is also `button_index`); neither closes nor navigates. A `widgetId` of `0` is kept as `"0"` rather than read as no id at all. Hosts: every host. */ trackClick(widgetId?: string | number): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records `in_app_rated` with the rating. Hosts: every host. */ trackRating(rating: number): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records the event with the campaign, delivery and message always attached; the location and date objects are merged into its properties. At most 20 a display, and a repeat of one name within 250 ms is dropped. A name starting `in_app_` or reserved by the SDK is refused. The fifth and sixth arguments are accepted and IGNORED: a message on screen is activity, and the campaign is always attached. Hosts: every host. */ trackEvent(eventName: string, generalAttrJson?: string | Record, locationAttrJson?: string | Record, dateAttrJson?: string | Record, isNonInteractive?: boolean, shouldAttachCampaignMeta?: boolean): Promise<{ ok: true } | { ok: false; reason: string }>; /** Refuses, and lint flags it at publish. Who a device belongs to is decided by the app, never by a message. Hosts: every host. */ identifyUser(idOrAttributes: string | Record): Promise<{ ok: false; reason: 'identity_from_message' }>; /** Refuses, and lint flags it at publish. Who a device belongs to is decided by the app, never by a message. Hosts: every host. */ setUniqueId(uniqueId: string): Promise<{ ok: false; reason: 'identity_from_message' }>; /** Refuses, and lint flags it at publish. Who a device belongs to is decided by the app, never by a message. Hosts: every host. */ setAlias(alias: string): Promise<{ ok: false; reason: 'identity_from_message' }>; /** Keeps the address as this person’s opt-in (the in-app form’s `save_as` path), signed in or not; never changes who they are. Hosts: every host. */ setEmailId(email: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Keeps the number as this person’s opt-in, as `setEmailId` does. Hosts: every host. */ setMobileNumber(mobileNumber: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Sets the trait `name`. Hosts: every host. */ setUserName(value: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Sets the trait `first_name`. Hosts: every host. */ setFirstName(value: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Sets the trait `last_name`. Hosts: every host. */ setLastName(value: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Sets the trait `gender`. Hosts: every host. */ setGender(value: 'male' | 'female' | 'other'): Promise<{ ok: true } | { ok: false; reason: string }>; /** Sets the trait `birth_date` (an ISO 8601 date). Hosts: every host. */ setBirthDate(value: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Sets the trait `location`. Hosts: every host. */ setUserLocation(latitude: number, longitude: number): Promise<{ ok: true } | { ok: false; reason: string }>; /** Sets a trait the template declares in its manifest; a platform trait or an undeclared one is refused. Hosts: every host. */ setUserAttribute(name: string, value: string | number | boolean): Promise<{ ok: true } | { ok: false; reason: string }>; /** As `setUserAttribute`, for a date. Hosts: every host. */ setUserAttributeDate(name: string, iso8601: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** As `setUserAttribute`, for a location. Hosts: every host. */ setUserAttributeLocation(name: string, latitude: number, longitude: number): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records the click, then hands the app a screen and its key-values (`setClickActionListener`, the iOS delegate, `inAppCampaignCustomAction`; on the web, the `TREEBARS_ONSITE_MESSAGE_CLICKED` event). Hosts: every host. */ navigateToScreen(screenName: string, dataJson?: string | Record): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records the click, then opens the deep link. Hosts: every host. */ openDeepLink(url: string, dataJson?: string | Record): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records the click, then opens the page in an in-app browser (a new tab on the web). Hosts: every host. */ openRichLanding(url: string, dataJson?: string | Record): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records the click, then opens the page in the system browser (this tab on the web). Hosts: every host. */ openWebURL(url: string, dataJson?: string | Record): Promise<{ ok: true } | { ok: false; reason: string }>; /** Copies the text, and shows `message` as a toast. `navigator.clipboard.writeText` inside a message is routed here, because a sandbox or a WebView usually refuses it. Hosts: every host. */ copyText(text: string, message?: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Opens the dialer with the number. Hosts: every host. */ call(mobileNumber: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Opens the SMS composer with the number and the text. Hosts: every host. */ sms(mobileNumber: string, message?: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Opens the share sheet (on the web, where the browser has one). Hosts: every host. */ share(text: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records the click with the action’s name, then hands the app the action and its payload: the app subscribes with `onAction(name, …)` on every SDK, and one fired before it has is held for a few seconds. `navigate` is reserved, with `{ screen, props }`. A name that is not lower-case letters, digits, dots and underscores, or a payload over 4 KB, is refused. Hosts: every host. */ appAction(name: string, payload?: string | Record): Promise<{ ok: true } | { ok: false; reason: string }>; /** Records the click, then hands the key-values to the app: `setClickActionListener` on Android, the delegate’s `inAppClicked` on iOS, `inAppCampaignCustomAction` in React Native, `TREEBARS_ONSITE_MESSAGE_CLICKED` on the web. An object is accepted as well as a JSON string. Hosts: every host. */ customAction(dataJson: string | Record): Promise<{ ok: true } | { ok: false; reason: string }>; /** Asks for push permission, and resolves with the answer. Hosts: every host. */ requestNotificationPermission(): Promise<'granted' | 'denied' | 'unsupported'>; /** The same as `requestNotificationPermission`, under the name iOS developers expect. Hosts: every host. */ showPushOptIn(): Promise<'granted' | 'denied' | 'unsupported'>; /** The same as `requestNotificationPermission`. Hosts: every host. */ handleNotificationPopUp(): Promise<'granted' | 'denied' | 'unsupported'>; /** Opens this app’s notification settings. Hosts: Android and iOS. */ navigateToNotificationSettings(): Promise<{ ok: true } | { ok: false; reason: string }>; /** Opens this app’s settings. Hosts: Android and iOS. */ navigateToSettings(): Promise<{ ok: true } | { ok: false; reason: string }>; /** Resolves the locale, direction, theme, platform, safe-area insets, the screen on show, the delivery and campaign, and the bridge version. Hosts: every host. */ getContext(): Promise<{ locale: string; direction: 'ltr' | 'rtl'; theme: 'light' | 'dark'; platform: 'android' | 'ios' | 'web'; insets: { top: number; right: number; bottom: number; left: number }; screen: string | null; deliveryId: string; campaignId: string | null; bridgeVersion: number; preview: boolean }>; /** Goes to a screen, and records `in_app_screen_viewed` with `how: "jump"`. Hosts: every host. */ showScreen(screenId: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Goes to the next screen. Hosts: every host. */ nextScreen(): Promise<{ ok: true } | { ok: false; reason: string }>; /** Goes back to the screen before. Hosts: every host. */ previousScreen(): Promise<{ ok: true } | { ok: false; reason: string }>; /** Keeps a value across this display’s screens. Hosts: every host. */ setState(key: string, value: unknown): Promise<{ ok: true } | { ok: false; reason: string }>; /** Reads a value `setState` kept. Hosts: every host. */ getState(key: string): Promise; /** Checks and submits the screen’s inputs, and records `in_app_form_submitted`. Hosts: every host. */ submitForm(formId?: string): Promise<{ ok: true } | { ok: false; reason: string }>; /** Asks the server for a reward from a pool, which it decides — never the page. Until games land (H6) it resolves `{ ok: false, reason: "not_available" }`. Hosts: every host. */ claimReward(poolId: string): Promise<{ won: boolean; prize?: string; code?: string } | { ok: false; reason: string }>; /** Shows the store’s review prompt. Hosts: Android and iOS. */ requestStoreReview(): Promise<{ ok: true } | { ok: false; reason: string }>; /** Tells the host how tall the content is; the Screens runtime calls it by itself, and the shim measures when no height is given. Hosts: every host. */ resize(height?: number): Promise<{ ok: true } | { ok: false; reason: string }>; /** Reads a value kept for this person and this campaign, on our server — so a seven-day challenge keeps its streak across days and devices. Also readable at send as `{{ template.stored. }}`. Hosts: every host. */ getStoredValue(key: string): Promise; /** Keeps a value for this person and this campaign (at most 32 keys, 1 KB each). `null` removes it. Hosts: every host. */ setStoredValue(key: string, value: string | number | boolean | null): Promise<{ ok: true } | { ok: false; reason: string }>; } declare global { interface Window { treebars: TreebarsBridge; } var treebars: TreebarsBridge; }