fastest way to send notification to all user laravel - laravel

I am building an app in laravel where I send a mail notification to all users once a new channel I create. So far I am using
$users=User::all();
\Illuminate\Support\Facades\Notification::send($users,new NewChannel($channel));
To send a notification to all users. Is there any package or way that would make the process faster? It is already taking years just with 5 users

You can look into queues to make the request more responsive, though it will take the same time to process the mails but it will happen in background. Another approach would be to use a third party service like sendGrid to take away the processing from your end.

Related

How to make Slack app send a private message via an incoming webhook to someone specific?

I created a Slack app that sends a series of interactive messages to a channel. In my Slack API dashboard, I see that I can create and remove hooks. Right now the hook url that I have set up in my code is the one for the Slackbot channel.
But the problem is that such a message only gets sent to me.
I want to send the Slackbot messages to Alice in situation A, and to Bob in situation B. Not just to myself, the guy who configured the app.
What's the best way to do this?
I would suggest that you should not use hooks for this. A more sane way to do this right would be via chat.postMessage Web API method which is documented here!
This is because hooks are tied to specific conversations and that approach quickly hits a wall on what it can really achieve, especially messaging different people. Once you start using the web API it's pretty simple. Just ask for the scope during app installation (remember to add that scope in your dashboard), subscribe to the event in your API dashboard and then you are good to go.
Everytime you send a message via that method, Slack will send you a payload which you can use for testing and logging etc.
You can see all the different ways to message programmatically inside Slack here.

How to get online users(in real time)

I have a task to display a list of online users present on the site. I've been said that I should use web-sockets for this.
I don't know how to implement this. I've already installed Pusher and Laravel Echo. Could you help me by pointing in right direction? I guess I should listen for the moment when user socket connects.
Reading all the comments I've imagined two possible solutions:
Broadcast when a user logs in / out
This is the very simple solution. You can use laravel notifications that allows you to implement a specific broadcast logic:
During the login / logout phase create a UserLogged[In|Out] notification and broadcast it to a specific channel
Using Laravel Echo and a "few lines" of javascript, update your onlineUsers list (for example in VueJs you may want to update the Vuex store)
But this may require a more complex logic and you may have to write a lot of code to keep the online users list updated... I think it's better to move to solution #2...
Use presence channels
I think this is the best way, since it doesn't require nothing else that a good Laravel-echo configuration. For the example I'm using Pusher (since you asked for), but this solution can be implemented with all the Laravel broadcast drivers.
When a user logs in, simply subscribe him / her to a presence channel (here the Laravel documentation)
Using Laravel Echo, subscribe the user to that channel
var chatRoom = Echo.join('my.chat.room.id');
Once subscribed use themembers.count method to keep an updated list of the channel users.
Using a setTimeout() function you can have a realtime update of the users list.
Notes
I've never implemented this solutions in a production environment, but just wrote some code to see how it works. so I think that if other people have diffent point of view or have a better way to explain this process I will be happy to update my answer.

Is it posible to send multiple message to Google Home through DialogFlow?

On facebook Chatbot or others platform we can send message directly to the user.
So for one question we can send multiple answer.
Now, that i'm developing for Google Home, I need to do the same.
I didn't find this opttion.
Dialogflow HTTP call to my server is the only output available.
So is there anything i missed to send message back to user in case I have a multiple messages answer?
(Or do I have to bufferise very message my hook creates before sending it back?)
Thanks
The conversation model for the Google Assistant is different - you can only send a message to the user in response to the user sending you a message. You can only send a single response, but it may have multiple parts (up to two Simple responses, containing messages, plus other features such as cards and carousels).
If you need to send multiple things back - you may need to rethink how you're doing it or how much you're sending back at a time. The Assistant is primarily for audible responses, and a long audible response is generally not a good UX.

How to run in background Laravel 5

Sending email with Laravel takes time before it is successfully sent, or sometimes it even fails. For this reason I would like to store record in database first and running email sending in background to save user's time. After storing the record, I would like to quickly redirect / refresh the page.
How do I use queue in below email sending code?
$message = new Applyonline($post_title, $cand_name);
$message->attachData($pdf->output(), $attach_name);
Mail::to($to_email)->send($message);
Please advise how to achieve this.
You can use Laravel Queues for this use the following link for complete explanation
Queue Thorough Explaination
I suggest looking into queues. Implementing this is quite easy. Just setup a queue for sending the mail and then add the queue to the mail facade. i.e Mail::to()->queue(new MailQueue);
Queues
Queueing mail

How does incoming mail notification on Gmail works?

I'm wondering how it's implemented in Gmail, that every time you receive e-mail, the list of mails is automatically refreshed. It looks like the server is sending some kind of event to the browser, but how is it possible? Or maybe it’s simle: the browser ask the server for new messages every let’s say 2 seconds? But it would probably kill the performance…
Anyone have some ideas?
EDIT: OK, so if it's the simple answer, how do they manage performance? When I send an email from an other account to the gmail account the view is "refreshed" almost instantly. You were saying about a simple function that returns true / false, but it must have some logic (db connection or reads some files). How they manage it?
See also: How is GMail Chat able to make AJAX requests without client interaction?
Dont know exactly which technoloy Gmail uses, but the concept is to open a channel - using reverse AJAX, comet or sprocket based techniques.
Think of it as the client requesting the server for data, but the server does not return for one minute unless it has new mail. Using this technique, the client can almost show the results in a real time manner and it does not have to poll every 2 secs. Makes sense?
gmail is, in fact, polling the server for updates. Not as often as every two seconds, though. That would be madness. A bit of testing with Tamper Data makes it look like maybe every 20 seconds, though there seem to be multiple events going through that confuse it a bit.
Regarding your edit, I imagine they might have a last-activity timestamp on the account tracking in their database, with the client polling query retrieving that via Ajax and comparing with its last sync to determine whether it needs to do a full update.
You have right with simple answer. Google Mail checking new messages on server via AJAX.
It must be some kind of ajax listener that get informations every X seconds.
I already set something like that for one of my projects. What I was doing is calling a function that was returning true or false. True if the page needed to be refreshed, false otherwise. Then if you have an update, you do another call to get the actual update. This way you don't have to refresh everything every time... but it's still intense on the server if you have a lot of users.
In other words and like chaos said, it's polling the server.

Resources