English
Open in Telegram

Thread @brunobr0wn my brother I work with flet_onesignal

4 messages · –
M
@brunobr0wn my brother I work with flet_onesignal I want know how to send notification to a one person on 2 not everyone U use this and it not work
  1. B
    Hey bro! There’s an important architectural detail about OneSignal here. 😊 1. The flet-onesignal is a client SDK; it DOES NOT send notifications All the package does within the app is: - request permission, - identify the user (login), - receive notifications, - manage tags, aliases, and opt-in/opt-out settings. The notification is always sent by the OneSignal server; you trigger the sending by calling the REST API (https://api.onesignal.com/notifications) from your own backend or through the web platform (https://dashboard.onesignal.com/apps). So the onesignal.login(...) you circled in the image is correct: it just binds that device to your external_id (in your case, the delivery worker's username). It doesn't fire any notification by itself — it only sets up the "address" so you can target that user later. 2. How to target 1 or 2 specific users Once each user has called login(external_id) in the app, you send the notification like this (from your backend or any Python script): import httpx # or requests ONESIGNAL_APP_ID = "your-app-id" ONESIGNAL_REST_API_KEY = "your-REST-API-KEY" async def send_to_users(external_ids: list[str], title: str, message: str): payload = { "app_id": ONESIGNAL_APP_ID, "target_channel": "push", "include_aliases": { "external_id": external_ids # e.g. ["john", "mary"] }, "headings": {"en": title}, "contents": {"en": message}, } async with httpx.AsyncClient() as client: r = await client.post( "https://api.onesignal.com/notifications", headers={ "Authorization": f"Key {ONESIGNAL_REST_API_KEY}", "Content-Type": "application/json", }, json=payload, ) print(r.status_code, r.json()) # To 1 person: await send_to_users(["john_driver"], "New order", "There's a new order for you!") # To 2 people: await send_to_users(["john_driver", "mary_driver"], "Notice", "Meeting at 6pm") Important points: - include_aliases.external_id is the recommended way in the SDK v5+ (which is what flet-onesignal uses). It's exactly the external_id you pass to onesignal.login(...). - If you'd rather target the device instead of the user, you can use include_subscription_ids with the subscription_id (get it via await onesignal.user.get_push_subscription_id()). - You need target_channel: "push" in the v5 API. 😉👍
    1. B
      In short, bro: login(external_id) on the client + a REST API call with include_aliases from the server. Those two together are what deliver a notification to 1 or N specific users. 😊
PPython Flet Global group🌐Python Flet Global group🌐@python_flet · group · Tech
615members10writing in 30 days
Venue feed Open in Telegram

An open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · Index limits · Remove a page · Catalog · Search · How we count