I'm a little stuck here.
I'm trying to hook a Calendar Push Notifications (https://developers.google.com/calendar/v3/push) to a Firebase HTTPS Function.
Pratically, I use a FF to create a calendar and I want to watch it for changes.
I authorized my domain and compose a request from the first function using the appspot service account ('#appspot.gserviceaccount.com') with the scope 'https://www.googleapis.com/auth/calendar' but I always received the error message: "Unauthorized WebHook callback channel: https://******.cloudfunctions.net/calendarWebHook"}],"
I'm trying to understand if the service account doesn't have the authorization to create the watcher or the webHook or something else.
Related
Is there a way to trigger a firebase function or create an item in Firestore when an email is received on Gmail or Outlook.
I'm trying to recreate on of ServiceNow's features where in if the helpdesk email address has received an email, it will automatically create a ticket (to firestore) out of it.
Thank you!
Here is one possible solution for Gmail (untested):
According to the Gmail API documentation:
The Gmail API provides server push notifications that let you watch
for changes to Gmail mailboxes... Whenever a mailbox changes, the Gmail
API notifies your backend server application.
...
The Gmail API uses the Cloud Pub/Sub API to deliver push notifications.
Since you can trigger a Cloud Function whenever a new Pub/Sub message is sent to a specific topic you can do as follows:
Set up a Cloud Pub/Sub client.
Using your Cloud Pub/Sub client, create the topic that the Gmail API should send notifications to.
Configure the Gmail account(s) to send notifications for mailbox updates
Write a Cloud Function that is triggered whenever a new Pub/Sub message is sent to this topic and execute the desired Business Logic (e.g. write to Firestore)
For Outlook, this SO answer indicates that it should be possible to call an API when a new mail is received. You could either call an HTTPS Cloud Function or directly the Firestore REST API.
I'm in the final stages of development for my new mobile app, but can't seem to find a way to allow Google Play Real-Time Developer Notifications to communicate to a firebase cloud function via the recommended Google Pub/Sub method.
The expected payload flow should go as follows:
User Purchases Subscription via Play Store > Play Store sends R-T Dev Notification to Pub/Sub > Pub/Sub sends message across to firebase cloud function > Cloud function runs with payload.
I currently have an Apple Developer webhook set-up in a similar way, which webhooks a receipt payload to an iOS cloud function I have setup.
During the pub/sub setup phase, the Pub/Sub page asks to verify the cloud function URL, which I cannot do as I am not the true webmaster of cloud function domain, hence halting me about halfway down the 'Add real-time developer notification' docs that google supplies.
Is there a way to get the RT notification to either a Pub/Sub cloud function or a HTTPS cloud function bypassing the google Pub/Sub and going directly to the webhook or another way to complete the flow above?
The ultimate aim is to provide a way to ensure the purchase made is actually a valid purchase, and not a forged request made by someone intercepting the client > server webhook and submitting one of their own accord.
After creating the new topic you DO NOT have to create manually a Pub/Sub subscription as explained in the documentation.
To make it work with firebase you have to deploy a new cloud function like this:
exports.YOUR_FUNCTION_NAME = functions.pubsub.topic('YOUR_TOPIC_NAME').onPublish((message) => {
// Decode the PubSub Message body.
const messageBody = message.data ? Buffer.from(message.data, 'base64').toString() : null;
// Print the message in the logs.
console.log(`Hello ${messageBody || 'World'}!`);
return null;
});
Please note that you need to replace YOUR_FUNCTION_NAME and YOUR_TOPIC_NAME.
When the deploy of this function finish, you will finally find the function in the subscription list.
At this point, you can edit the params of the automatically created subscription, and you will find the url endpoint already filled with an internal url.
Here you can find an example: how to setup a PubSub triggered Cloud Function using the Firebase SDK for Cloud Functions.
I'm wondering if it is possible to get a response message when Firebase Cloud Function is executed succesfully.
The case is I'm trying to send an email, but I would like to make sure it is sent and received by the receiver.
If you use Sendgrid to send emails, as recommended by Firebase (see https://github.com/firebase/functions-samples/tree/master/quickstarts/email-users), you can use Sendgrid's Events Webhooks, see https://sendgrid.com/docs/for-developers/tracking-events/event/#engagement-events and https://sendgrid.com/docs/for-developers/tracking-events/getting-started-event-webhook/.
As explained in the last link above, "SendGrid's Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email. "
You just have to setup an HTTP Cloud Function that will be called by Sendgrid for the events of your choice.
Goal
I would like Slack to trigger a Firebase Cloud Function.
Example: A user sends a Slack message, and Firebase Cloud Functions writes part of the message to the Firebase Database.
Tools: Slack API \ Event Subscription, googleapis, nodejs, etc.
Issue
The Slack documentation here describes the challenge response requirement.
Once you receive the event, respond in plaintext with the challenge
attribute value.
However, I'm not sure how to let Firebase know the Slack request is authorized. An HTTP request to Firebase Cloud Functions must include a Firebase ID. I've let googleapis do the work of setting up the Firebase ID, and I don't see a way to alter Slack's initial verification request (if I had an ID to provide)
What's the best way to trigger Firebase with the Slack API?
Getting Slack to verify the Firebase URL is pretty easy.
Solution
Google Firebase Cloud Function
import * as functions from "firebase-functions";
export const helloSlack = functions.https.onRequest((request, response) => {
if (request) {
response.status(200).send(request.body);
} else {
console.log("Request Error...");
throw response.status(500);
}
});
Steps
Deploy your Firebase Cloud Function
Goto https://api.slack.com/apps
Your App > Event Subscriptions > Enable Events
Turn on Events
Enter your Firebase Cloud Functions URL
tl;dr
Slack instructions:
We’ll send HTTP POST requests to [your] URL when events occur. As soon
as you enter a URL, we’ll send a request with a challenge parameter,
and your endpoint must respond with the challenge value.
Cloud Function URL:
https://firebase-slack-adaptor.cloudfunctions.net/helloSlack
To meet the verification challenge, enter your Firebase Cloud Functions URL (example above) in Slack's Request URL field.
Your Firebase Cloud Function should return the body of the Slack request. Slack finds what it needs in request.body and should verify your URL.
I have made an app with the use of firebase. It is basically a chat application in which you van send and receive the text and images. I want to add a functionality in it that whenever a user sends a msg, then another user should get a notification . When I try to send a notification through the firebase console, then it is working, but when a user messages through the app, then it is not showing any notification to another user. So, can anyone tell me that how can this functionality be achieved ?Also, provide some sample code to see how things are working
You need to use cloud functions for that:
https://firebase.google.com/docs/functions
Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests
First, you can register the user to a topic:
FirebaseMessaging.getInstance().subscribeToTopic("news");
https://firebase.google.com/docs/cloud-messaging/android/topic-messaging
Then when the message is sent to the database, you can use onWrite() in cloud functions which is a database trigger to be able to send the notification.
https://firebase.google.com/docs/functions/database-events