Is there some way to send push notifications using Parse and a web service built in Django? I mean, I have a dashboard built in django, in this dashboard I can set it up some parameters, when I create for example a new news, this has to be notified to the user through a push notifications. How can I achieve this?
See that page... https://www.parse.com/docs/rest/guide you should try make a request similar to this....every time you make some news
import json,httplib
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('POST', '/1/classes/GameScore', json.dumps({
"score": 1337,
"playerName": "Sean Plott",
"cheatMode": False
}), {
"X-Parse-Application-Id": "${APPLICATION_ID}",
"X-Parse-REST-API-Key": "${REST_API_KEY}",
"Content-Type": "application/json"
})
results = json.loads(connection.getresponse().read())
print results
Related
I use django channels 3.0.0 and websocket using angular.
But users connect to django websocket and they are in their own rooms respectively.
And when I want to send the event to connected users outside of consumers, I used the following code.
all_users = list(Member.objects.filter(is_active = True).values_list('id', flat = True))
for user_id in all_users:
async_to_sync(channel_layer.group_send)(
"chat_{}".format(user_id),
{ "type": "tweet_send", "message": "tweet created" }
)
And in consumers.py, my consumer class's chat_message function
async def tweet_send(self, event):
content = event['message']
# Send message to WebSocket
await self.send(text_data=json.dumps({
"type": "MESSAGE",
"data": content
}))
And this "self.send" function is meant to be sent to all connected users respectively, but when I run the code, the all data are sent to only one user who has connected the last time.
I don't know why. If anyone knows the reason, please help me.
This is indeed a bug in version 3.0.0. It was reported and fixed in 3.0.1.
I am working on integrating GMB into some of our internal apps, and would like to set up to receive real-time notifications for reviews and questions.
I have created a topic, and a subscription with a valid URL.
The next step is to tell GMB to send the notifications to the topic, and I believe the endpoint is the one below. However, it is very vague about the parameters it wants.
This is the documentation
https://developers.google.com/my-business/reference/rest/v4/accounts/updateNotifications
It wants a "Notification Settings Resource Name" in the URL, but it's not explained anywhere what that actually is. I have tried every possible value, but always get a 404 error response with the message "Requested entity was not found."
Has anyone successfully set this up? What values does the "getNotifications" endpoint want, and where in the various dashboards can this be found or created?
Any help is much appreciated!
As mentioned in the comments, you need to send the accountId as part of the URL.
To find this, you will first need to send a GET request to
https://mybusiness.googleapis.com/v4/accounts
This will return something along the following lines:
{
"accounts": [
{
"name": "accounts/102647145453118950380",
"accountName": "Tom Spencer",
"type": "PERSONAL",
"state": {
"status": "UNVERIFIED",
"vettedStatus": "NOT_VETTED"
},
"profilePhotoUrl": "//lh3.googleusercontent.com/a-/AOh14GgPkuJj03DeCa1isBAJALY4eOl09WGYVFrM4mG5=s132"
},
]
}
You can see here that accounts/102647145453118950380 is returned in the name field. Take this field, and construct the following URL:
https://mybusiness.googleapis.com/v4/accounts/102647145453118950380/notifications
Send a PUT request to this URL, with a request body resembling the following:
{
"topicName": "projects/{projectId}/topics/{topicId}",
"notificationTypes": [
"NEW_REVIEW",
"UPDATED_REVIEW"
]
}
Assuming you have pub/sub setup as per the documentation, this should send a message to your topic/subscribers whenever a new review is created or a review is updated.
I have a website written on Flask, and I would like to update it when answers to a Google Form has been submitted.
More precisely, I have already associated the form to a Google spreadsheet and I can read that spreadsheet from Flask, but the key component missing is how to trigger the website to update its content when new answers have been submitted to the form.
What would be the best way to do this?
Webhook solution:
Google Forms:
Enter the Google Forms editor
Click 3 vertical dots next to profile picture, and select 'script editor'
Customize this snippet to your WebHook url and set a custom token (this is not really secure, but better than nothing ).
function onFormSubmit(e) {
const url = "https://example.com/webhook";
var options = {
"method": "post",
"headers": {
"Content-Type": "application/json"
},
"payload": JSON.stringify({"token": "sometokenheretocheckonbackend"})
};
UrlFetchApp.fetch(url, options);
}
( Dialog may popup where you have to approve that you connect to an unauthorized service )
Handling on the Flask side:
from http import HTTPStatus
from flask import (
abort,
request
)
#blueprint.route('/webhook', methods=['POST'])
def handle_webhook():
payload = request.get_json()
if payload.get('token') != "sometokenheretocheckonbackend":
abort(HTTPStatus.UNAUTHORIZED)
# Update your content
return jsonify({'success': True}), HTTPStatus.OK
Periodic updates (Alternative solution):
I would consider launching a daemon Thread that periodically updates this content. This is obviously not as elegant, but should work quite stable and wouldn't be much more demanding for the server if the content update procedure is reasonably lightweight.
You could create an Form Submit trigger to trigger a Google Apps Script function that calls out to your Flask site and triggers the update.
https://developers.google.com/apps-script/guides/triggers/installable
I am trying to use the drive API to test watching one of my google drive's documents...
I have created a localhost server using python flask...
This is my code for it
from flask import Flask, render_template, request, url_for
app = Flask(__name__)
#app.route('/')
def display():
user = {'nickname': 'Miguel'} # fake user
return '''
<html>
<head>
<title>Home Page</title>
<meta name="google-site-verification" content="XXXX" />
</head>
<body>
<h1>Hello, ''' + user['nickname'] + '''</h1>
</body>
</html>
'''
if __name__=='__main__':
app.run()
#app.route('/hello', METHODS=['POST'])
def hello():
return request.get_data()
I use ngrok to connect my localhost to the internet...
This doesn't even matter however because the drive API cannot connect to the server
as when I use the Google Drive API in the API explorer it gives me
{
"error": {
"errors": [
{
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://44c689c2.ngrok.io"
}
],
"code": 401,
"message": "Unauthorized WebHook callback channel: https://44c689c2.ngrok.io"
}
}
The items that I put into the body are:
{
"address":"https://44c689c2.ngrok.io",
"type":"web_hook",
"id":"abc123"
}
Is there any way to fix this?? Thanks...
You have the same issue in this post.
To use Push Notifications in Google Calendar make sure you
followed the instructions here:
Register the domain of your receiving URL in Google Dev Console. Go to Credentials and click Domain Verification for the webhook setup.
For example, if you plan to use
https://yourdomainexample.com/notifications as your receiving URL,
you need to register https://yourdomainexample.com. Set up your
receiving URL, or "Webhook" callback receiver.
This is an HTTPS server that handles the API notification messages that are triggered when a resource changes.
Set up a notification channel for each resource endpoint you want to watch.
A channel specifies routing information for notification messages. As
part of the channel setup, you identify the specific URL where you
want to receive notifications. Whenever a channel's resource changes,
the Google Calendar API sends a notification message as a POST request
to that URL.
You may also check this this SO thread.
I currently have the below that updates an OTRS ticket using by calling the link /otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket
It works great, but how can I get it to send an email to the customer when the ticket is updated as well?
var body = JSON.stringify ({
"Ticket":{
"StateID":params.state},
"Article":{
"ArticleTypeID":params.noteType,
"Subject":params.subject,
"Body":params.bodyText,
"ContentType":params.contentType
}
}
);
//Build the full URL for our webservice query.
var LoginURL = authenticate.URL + "/" +
TicketID +
"?UserLogin=" + authenticate.UserLogin +
"&Password=" + authenticate.Password;
//Perform the actual work. As well as the URL of the webservoce
var client = new apiclient.ApiClient({ serverid: this.serverid });
var resp = client.invoke( "formutils", "httpRequest", {
"url": LoginURL,
"method": "POST",
"headers": {
"ContentType":"application/json"},
"body": body
});
If you update a ticket via the web service API, by default this will NOT trigger sending an email to the customer, not even if you set the article type as 'email-external'.
If you do want this to happen, the best way is to create a new Notification (prior to OTRS 5 this would be an 'Event Based Notification') as described here: http://otrs.github.io/doc/manual/admin/stable/en/html/administration.html#adminarea-ticket-notifications
You can match on the ArticleCreate event, the user who created the ticket via the Web Service, and maybe other attributes as well.
https://github.com/OTRS/otrs/blob/6c87d2b1370b917629a99df7e080b8f87f051581/Kernel/GenericInterface/Operation/Ticket/TicketUpdate.pm#L1936 calls the internal API ArticleCreate() which never sends email whereas ArticleSend() does.
There is an extension published by Znuny which you could install on your OTRS system that exposes this functionality to the web service as well: https://github.com/znuny/Znuny4OTRS-GIArticleSend