Is there a way to send push notifications with Django - django

Hello I wonder is there a way to send push notifications with Django to a user.
I have a website that accepts/refuses vacation demands.
When a user sends a vacation demand my Django app sends email to the CEO to notify him that there was a new vacation request.
When the CEO accepts the demand it sends email to the user that the demand was accepted.
But since the CEO receives plenty of emails a day and he barely sees my emails i would like to make a browser notification whenever he opens the browser to see notification from my website that a demand is waiting to be approved/refused.
Is there a library that can do that for me,
I've tried django-webpush but I couldn't managed it to work even though I
followed all the steps.

Yes you can, since your have the information that your user accessed your server at least once. checkout this lib
https://github.com/jazzband/django-push-notifications
EDIT Gonna put more information about it
If you expect receive one response from your backend to your backend you can write some watcher to receive new data, or create one plugin, or use sockets or even make your frontend send one call to backend with some interval time to check if there is any new messages...
Lets split up a bit
1 - Watcher
Using watchers you can just watch your backend to any changes... build it from scratch i thing i a bit "hard", you can use some modern frontend framework that already have it like Angular, React, Vue... and capture new incomes messages from your backend and create Notification instance in your browser and your it to your user (i guess they will have to keep the page openned to do it... im not 100% sure)
2 - Plugins
You can build one plugin to add to your browser and receive the data from your server... since you already in browser is more easier to use browser functions
3 - Sockets
The common way to make 2 ways comunication from frontend to backend, most used with chats and things arround that, just create one channel of communications between this 2 sides and you will be able to send and receive messages from frontend or backend
4 - Dirty Way
If you not get the time to implement it like supposed to do with quality you can go the dirty way, just setup one ajax in your page to check your backend to new messages every 5 minutes? or more or less... and if find any new data (of course you will have to handle it on your backend like any other suggestions above) and then you create one new notification in your browser and show to your user...
Im sure there is bunch of libs that already do most of things to you, so just search a bit and test until you find anything that fits your need

Related

Refresh a page when something new appears in Django

I'm creating a website for a local establishment that uses Ifood. Ifood provides an API that allows you to check information, both regarding establishments and incoming orders.
The code is ready, but I can only show a new order update when manually refreshing the page. Which is a bit shippable. I thought about putting an automatic update with JavaScript at the given time, but it would be an ugly workaround.
In this case, I'm getting JSON data, but in a more general context.
How could I refresh the page as soon as new data appears?
An automatic update with Javascript might not be as dirty as you think. Even smartphone push notifications are really just occasionally polling under the hood.
If you really want to push from your server, WebSockets or server-side events are what you want. Unfortunately, it seems this kind of setup is not natively supported by Django.
Another option could be to use a paid service like Pusher.com. Such services usually let you listen for an even in JS, then call an API endpoint to trigger it from your server. This will work well on Django or any other server setup.

Dialogflow chatbot async

I am using Dialogflow with the the V2 C# client library. When the user provides the Chatbot with an address, I use a web-hook to send the address to my back-end.
My back-end then validates the address and does some other things (my back-end takes about 2 seconds).
However, I would like the chatbot to respond to the user with something along the lines of "Give me a second and I will validate the address you provided me" before my back-end has finished.
Then once my back-end has finished, respond to the user with the results of the address validation. I don't want to accept input during the 2 seconds my back-end is processing.
In summary, I would like to know, what is the best way to acknowledge a user's input with a message, not accept any further input until my back-end processing is complete and then finally responding to the user with the results of my back-end?
You need to manage this via contexts. If you are using Dialogflow SDK instead of the UI, you could control all of this via code which is more convenient.
If you are using the GUI, set an input_context and give it some lifetime as you see fit. On your web-hook's successful resolution, update or cancel respective input_context via an output_context to demonstrate completeness of a request.
By using contexts event if user asks any other question, you will not loose previous question and its answer will still be rendered to user.
Disengaging the chatbot by not taking any questions might not be a good user experience. If you really wanted to do it, you will need some JS to help you create a loading/processing sort of icon on your bot's interface for specific intents while you programatically control the mute & unmute commands on the UI.

Send a post request to server

I am fairly new in web development and I decided to handle a user's availability to send a POST request to server. However, I do not know even whether it is possible or not but when a user close my Django site without using logout button (For example close the browser or tab), in order to understand the user is offline or online, I want to send a request to server. As a result, when the server does not get an answer from the user for a while, it automatically logout the user.
Can you tell me is it a good way to handle a user's availability and first of all is it a realistic solution? If it is, can you suggest me a document or example that helps me please.
I agree to to the answer of #Mounir. That's not related to django, if you want to know when a user is "disconnected"(close the tab or window) you need to use javascript, in concrete you need to use Sockets.
I recommend you this ones:
http://socket.io/
https://github.com/centrifugal/centrifugo
I'm using centrifugo for one project right now. In concrete, for chat and inbox messaging. It's very simple to make it run with Django.
Greetings
For logging out user you can use the Session expiration, but for all other staff you want to achieve I don't see any thin really related to Django itself, everything depend on your requirements and is more Browser/javascript related than Django.

Track emails to clients within web application

I am developing a Django-based system. It is kind of client-tracking tool.
Some users can work with different client accounts.
I would like to track the emails among users and clients within the application.
The company uses MS Outlook Server as a mail server and users are sending emails from their workstations.
The goal is to have the list of emails to/from users/client on the web page.
I see some possible ways how to do this.
Make the email form on the web page and send all emails from this page. Thus we can store the email sent.
While sending the email - manually add a CC field with the address of robot who will have access to this mail thread and can fetch messages from the inbox sorting them by the sender/recipients.
Automatically fetch messages from user mailboxes (don't want to store their passwords though)
Probably use some mail filter on the mail server to forward messages from/to specified address (don't know how to do this)
But maybe someone can give some advices? Any ideas, guys?
I had done something similar a couple years ago (with Postfix, however, not with MS Exchange).
The best approach IMO is to setup a mailserver to blind-copy each email to your script. In Postfix this called a "custom transport". This way your clients will be able to send emails using any program, not necessary through a web form. AFAIK, nearly all production email archiving solutions work that way.
Sounds like you are looking for something like the journaling feature in microsoft exchange-server. It allows you to define a special mailbox that will recieve a copy of all mails. You can find more information about this here, here and here
Once all the messages are in one mailbox you can access it from your application.

What Web Applications Do You Know Using Webhooks

Description of how a webhook works from http://webhooks.pbwiki.com/ -
How do they work?
By letting the user specify a URL for various events, the application will POST data to those URLs when the events occur...Among other things, you can:
create notifications to you or anybody via email, IRC, Jabber, ...
put the data in another app (real-time data synchronization)
process the data and repost it using the app's API
validate the data and potentially prevent it from being used by the app
Who is using web hooks?
DevjaVu, BitBucket, GitHub, Shopify, Versionshelf, PayPal (IPN), Jott (Links), IMified, PBwiki, Facebook (Platform, sort of), Mailhook.org, SMTP2Web, Astrotrain, Notifixious, Assembla, ZenDesk, Google Code
Do you know of any good uses of webhooks?
AlertGrid is the webhook consumer. You can configure it to accept http calls from ANY source and raise alert (email, sms, phone) to a specified person or group of people (works worldwide!) whenever the parameters in the http callback meet your criteria or when the http call was expected but it didn't occur (kind of 'heartbeat' monitoring). There is a visual editor for you to easily create rules.
Apart from notifying people by sms or email it can also notify existing applications by sending the http requests to their APIs.
It can also visualise data received in http callbacks and show the history.
Unfortunately, the wiki is not the most up to date list of known implementations. I have my own list that I'll put on the wiki when I get around to reorganizing it. Some not mentioned in the current list:
Dropbox
Gnip
Google Code (Project Hosting)
Checkout by Amazon (both for notifications and as actual callbacks with return data)
Hubilicious
Beanstalk
Google Checkout
MailChimp
SurveyGizmo
Hey!Watch
MySpace (for app developers)
I know shopify is using webhooks quite successfully now. By extension so is fetchapp uses them as well. You either are sending an xml file, or receiving one and doing your own processing logic on it.
Oh and shopify's wiki in the link has a whole write up about how to implement it in your app.
OfficeAutopilot has an interesting version of webhooks.. they use their rule interface to trigger API posts. Can trigger in response to any system event.. email opens, clicks, page visits, purchases, etc, etc.
Kiln 1.2 uses webhooks much like GitHub, BitBucket, etc.
(Disclaimer: I'm a Kiln/FogBugz dev.)
Say for example you want to get data from any API( eg. twitter, facebook etc.,). Instead of you polling the data for every few minutes/seconds, it POSTS the data to the specified URL, whenever it is available.
By using this, you will avoid unnecessary polling like say you poll and data is not there yet.
StorageRoom is a JSON-based CMS that supports webhooks, so that you can notify other services or kick of some manual processing on your own servers.
(Please note: I created the service myself)
If you want to connect one service that supports webhooks to another service's API, you can check out IronWorker's webhook support. Here's a blog post that walks through connecting github webhooks to HipChat:
http://blog.iron.io/2012/04/one-webhook-to-rule-them-all-one-url.html
There are some other examples here too, one that takes a chargify callback and posts to Campfire.