Back

Listen to function parameter in realtime

  • 0
  • Self Hosted
  • Functions
  • Apple
  • Realtime
nishp77
22 Jun, 2023, 18:02

When a function is execute from client side with parameters can we listen to those parameters as well in realtime when subscribing?

TL;DR
The user wants to listen to function parameters in real-time and avoid saving them in a database. The suggested solution is to use the Appwrite Realtime permission module. The user can subscribe to a specific channel and give read permission to the nearest driver when a new ride is created. If the driver refuses, the permission can be removed and given to the next nearest driver. When a driver takes the ride, the document can be deleted. There is currently no way to directly listen to the parameters sent to a function in real-time.
Binyamin
22 Jun, 2023, 18:04

You mean to know which parameters were sent to thet function?

nishp77
22 Jun, 2023, 18:04

yes

Binyamin
22 Jun, 2023, 18:05

Mmm, That sounds like something good to have, But, as of now function executions events return Execution object https://appwrite.io/docs/models/execution

Binyamin
22 Jun, 2023, 18:06

It seems like it doesn't contains the sent data.

nishp77
22 Jun, 2023, 18:06

I read the execute object, I wanted to notify drivers when a client books for a ride

nishp77
22 Jun, 2023, 18:07

Do you know any approach or I have to save in db for this?

Binyamin
22 Jun, 2023, 18:08

Can you elaborate a bit more?

nishp77
22 Jun, 2023, 18:09

I was like when a customer books for a ride, I have a function that gets nearby drivers like 5 in a list and we can subscribe to docID for location, then I want to notify the nearest driver, if he accepts or rejects I wanted functions and not saving into db as its too coupled up

nishp77
22 Jun, 2023, 18:13

Any suggestions?

Binyamin
22 Jun, 2023, 18:15

I'm thinking on something

nishp77
22 Jun, 2023, 18:17

was like if i had way on getting to know what parameter were sent then in realtime I listen that would solve my issue of not saving in db as it's resource intensive and some hacky way of notifying.

Binyamin
22 Jun, 2023, 18:17

So as of now you can notify a driver?

nishp77
22 Jun, 2023, 18:17

I can't

nishp77
22 Jun, 2023, 18:18

Like I want the parameter

nishp77
22 Jun, 2023, 18:18

I mean listening when function is executed in realtime no issue

Binyamin
22 Jun, 2023, 18:20

So to summarize

  1. Client ask for a ride
  2. Function will look for 5 near driver
  3. The nearest one will ask to take the ride
  4. If disagree will go to the next driver

This is the right flow?

nishp77
22 Jun, 2023, 18:20

Yes

Binyamin
22 Jun, 2023, 18:33

Okay, You can choose one of two approaches.

Using FCM/APNs

Use another service to push notification.

Pure Appwrite

One way is to do it with database - very small - as this will give you the best realtime option.

You won't need to create to many rows as of Appwrite special Realtime permission module.

All subscriptions are secured by the permissions system offered by Appwrite, meaning a user will only receive updates to resources they have permission to access.

Using Role.any() on read permissions will allow any client to receive updates.

You can let all the drivers to subscribe to a channel for __bidRides __collection databases.[ID].collections.bidRides.documents, But in default no-one will have permission to the collection, which means no-one will get notification for a new / updated document.

So when a new ride came to the system you can:

  1. Create a new document for it inside the __bidRides __ collection.
  2. Give the nearest driver read permission.
  3. Update one attribute of the document.
  4. If the driver refuse, repeat step 2 and 3
  5. Remove the nearest driver permission
  6. Give the next nearest driver read permission
  7. Update one attribute of the document.

Then, when one driver took the ride, then you can just delete the document.

Hope it makes sense.

nishp77
22 Jun, 2023, 18:41

Thank you

nishp77
22 Jun, 2023, 18:52

Regarding APN is appwrite supporting at that the moment?

nishp77
22 Jun, 2023, 18:52

No

Binyamin
22 Jun, 2023, 18:53

Appwrite doesn't have - right now, as Wess and Steven said last week maybe on that topic - right now PN of it self. But I think you should be able to send APN using the Swift SDK.

nishp77
22 Jun, 2023, 18:55

Thanks alot

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more