Flutter/firebase: execute function at specific time - flutter

How can I execute a function at a specific time with flutter and firebase? I want to allow the user of my app to send messages to other users at a specific time. Right now, they are sent when the message is created, but I would like to allow the user to schedule the message.
Any idea? I have looked at the Timer class of Flutter, but it does not seem to be useful for this.

According to me handling this on flutter(frontend) will be a bad idea. You can look into firebase cloud function and scheduling of cloud functions to achieve the result. For example, you can have a boolean to show/hide the message in your message model and use cloud function to update it accordingly on the scheduled time.

Related

How to receive data from an api without any user interaction

I'm trying to receive some data from an API call and do some task based on the received data.
Let's say I have my flutter app opened and in that opened state without any click or any interaction I get some data or do any function when I send something through the API.
I used Firebase FCM to do such task - When I send something through the API the firebase notification captures that data and doing the tasks I want on the flutter app.
But I want to do without Firebase. How can I do that. Any solution/suggestions would be great. Thanks!
At first, let's put Flutter aside. Your problem is to pull data from API and do a specific task OR your API should notify the app through API.
For the first problem, a simple data polling should work: when the app is opened, you just start some kind of timer and periodically pull data from the API and do something. However, this method is not perfect, it drains the battery and in general, there are better ways to achieve the same thing, for instance using sockets or push notifications (as some of the answers already state that).
For your second problem - "or do any function when I send something through the API" - you need some kind of mechanism to notify your app for it to react and process the data. This one could be handled using the same mechanism as for the first problem.
So, probably you need to use some kind of push notification service (for instance OneSignal or Pusher, or any other similar service) or web sockets (https://flutter.dev/docs/cookbook/networking/web-sockets).
Your question is little bit unclear. Whatever if you want to do some network call even without any interaction by user you can call network in your onInit method. This method runs at the very beginning for individual screen. Then do your task based on the response
You need stream API for this,look into socket programming
You can use webs socket or pusher for this. When web socket is connected with your server that time you received some data and you can do your task.

Delay Google Cloud Function

I have a swift iPhone application paired with Google Firebase. Within the application the user will complete an action (press a button). At this point, I would like to schedule a Google Firebase Function to run 45 minutes after the user action. However, I would like this function to be able to be cancelled when another action (press a button) is completed within the iPhone application. I could do this within swift with a timer but that wouldn't work if the user closes the application.
I am not opposed to using a third party scheduler or something of the sorts. Any suggestion welcome.
I have looked at the possible duplicate questions and answers (Cloud Functions for Firebase trigger on time?) However, most of the links in that answer are deprecated and out of date. Also, that is referring to scheduling something repeatedly. For example, every hour, once a day, etc... I am looking to schedule the job 45 minutes after trigger (user action) with the ability to cancel the job within that 45 minute window.
Would a delayed Cloud Task work for you?
You can create a Cloud Task that is delayed and calls your function through an HTTP trigger. The task can be then cancelled if your user performs the second action you desribe. There is a number of dedicated client libraries for Cloud Tasks, as well as a REST API.
There is no built-in way to delay the trigger on a Cloud Function, or to re-trigger it after a certain delay. The best way I can think of using Cloud Functions is to set up a periodic trigger as shown here: Cloud Functions for Firebase trigger on time?. And then in that periodic trigger you determine what jobs have to run.
You could use https://delayedrequest.com as long as you can invoke your Firebase Function via an http request.
I recently had a similar issue that was solved by using Cloud Scheduler and Firestore. I set up a job that would trigger a cloud function every 5 minutes that would check a Firestore collection. It would retrieve the data on when a cloud function should be triggered and trigger it. It also depends how accurate you want your time triggers to be. It's not optimal to have it trigger all the time for no reason but in my case it worked.
Javascript/Typescript allows you to delay using the setTimeout function
// time is in milliseconds
function delay(time:number) {
return new Promise(res => {
setTimeout(() => {
res("VALUE TO RESOLVE");
}, time);
});
}
Then call this by doing const res = await delay(1000);

how to add progress message in google home dialogflow

In my conversation dialogflow, I would like to add some progress messages like hang in with me, I'm looking up for that data or similar in the conversation. Is there any guidance or best practice to do this?
Unfortunately, there is no good way to do this at this time. If your webhook takes longer than about 5 seconds, Dialogflow will return one of the default responses it is set with. If you're not using Dialogflow, the Action SDK will say your webhook isn't responding and will close the conversation.
There is currently no way to send a reply, and then send another reply without the user saying something first.
One workaround might be to have the default response be something like "I'm looking that information up. Ask me again in a few seconds." When your lookup finally completes, cache the information so when/if the user asks the question again, you can return it more quickly.
Depending how long it takes, you may also wish to register a dynamic reprompt. This will send an event to your webhook if the user doesn't say anything. In a situation like this, they may say nothing for a few seconds, but that may be long enough for you to have computed the reply. So after a few seconds of silence you can suddenly announce "I've figured it out, the answer you were looking for is..." or something similar. This has some limitations - you can only reprompt twice like this before Google sends you a final reprompt and closes the conversation.
Although the platform does support notifications, these are still in developer preview and don't work with all devices. They also don't quite continue the conversation (it doesn't just start talking) - they just send a notification to a phone that there is a message and that they can restart the conversation. Depending on your use case, this may be useful combined with the above.
Update
The Media Response includes a feature that we can take advantage of to handle this. Similar to the dynamic reprompt method above, you'll get a call automatically when the media you're playing ends. So you can play a short "hold music" and your webhook will be called when it is finished. You can then either give the result or say you're still working on it and play more hold music.

Running two api's simultaneously using GCD in ios

I am working on radio application where i need to convert speech to text. For that i am using third party api's. For geting better results i want to run two api's at the same time and compare the output. this should happen when user clicks on record button.
I know we can do this using GCD but not getting exact idea of how we can achieve this.
Need suggestion.
Thank you.
Th short answer is that you create two GCD queues, one for each Speech-to-Text task. Within each block, you call the two different APIs with the same input data. Then you either wait for the result, or get the block to invoke a callback status method when completed.
Note that you will need to ensure that the speech engines can safely run on background threads.
This is fairly straightforward if you want to record the audio first, then submit the data to two different engines for processing. But it sounds like you might want to start processing the audio as soon as the user clicks Record? In that case, it very much depends on the APIs as to how you feed them data in real time. You might want to just run them on separate threads explicitly and feed them data as it comes in.

How would I get SMS/Phone events, and act on them before they're sent to the system apps?

I'm trying to develop an application for a jailbroken iPhone similar to Mcleaner or iBlacklist.
What I want my app to be able to do is intercept SMS or Phone events and handle them before they're sent to the appropriate receiver. So for example, I want the application to get an SMS event, compare the sender to an array of numbers, and either process the data or ignore it and pass it off to the SMS app.
In MCleaner, you can define a blacklist of numbers, and if a text message is received that matches the blacklist the user won't get an alert from the phone and the data is instead handled by MCleaner.
How would I go about getting these events, and further, how would I get these before the appropriate apps receive them? From what I understand, I'd need to become a first responder for these things, but I really have no clue where to start. I can't seem to find any hints on how I'd go about this as this app will not be calling apple classes to get the data..
Thanks.
I can only guide in with this, sorry, the code isn't mine to give.
In memory, all the action calls are all just pointers. What you have to do is over ride the pointer to make it point to your own function. Once you do that, you do w/e you want in your function, and then call the default function call. This ensures the integrity of the action calls and allows you to intercept the actions.
You need to use the CKMessage class.
Check this out: http://hexorcist.com/private_frameworks/html/interface_c_k_message.html
and this: http://www.ifans.com/forums/showthread.php?t=232745