Response of cloud function - firebase

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.

Related

firebase function triggered on email received

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.

Enabling the notification feature for my firebase app

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

How to get Firebase ID Token in Firebase Cloud Functions on auth.user().onCreate event?

Background
I have some Endpoint APIs on App Engine. I am able to authenticate the Firebase User in my Endpoint API when making a call from my client. (I append the Bearer token to HTTP request header when making the call).
I want to create a Cloud Function that is triggered on User Creation in Firebase (referred this video tutorial). From this Cloud Function, I want to call an Endpoint API using HTTP Request. For the HTTP API call to work, I need to send a Firebase Token in the request header.
Question
How do I get current user's ID Token inside Cloud Function?
A related post here recommends that I should call the API from my Ionic/Angularjs client. However, that will be a roundtrip back to the client and then to Endpoints. I am trying to avoid that.
I found that in /node_modules/firebase-admin/lib/firebase-app.js, there is a call to "FirebaseAppInternals.prototype.getToken". But I am not sure how to call it from my Cloud Function.
Sorry if its a noob question. I am new to Javascript and NodeJs. Any pointers will be of great help!
Also, I am not using Custom Tokens.
Thanks!

Receiving Emails with Google Cloud Functions in Firebase

I'd like to build an email drop service. Is it anyhow possible to receive incoming emails with Google cloud functions, process them and store them in firebase db?
I'm thinking of something similar to Amazon simple email service SES in combination with lambda functions. Does any of the available email services like sendgrid, mailgun, postmark or any other has api's to trigger Google Cloud Functions on incoming emails?
Yes, services like Sendgrid and Mailgun allow you to set up webhooks for incoming mail. You can configure these webhooks to point to an HTTPS Cloud Function, at which point it will be invoked each time you get a new incoming email.

Amazon Simple Notification Service to http endpoint

I want to send message from Amazon Simple Notification Service(SNS) to the http endpoint. There is no proper solid documentation on how to do that. Though I had read Amazon SNS documentation still I could not get entire picture.
Can anyone give me simple example on how Amazon SNS and http endpoint work together?
There good documentation for what you asking: http://docs.aws.amazon.com/sns/latest/dg/sns-dg.pdf
Look at the page #147, it describes what steps you need to do for sending messages to HTTP(s) endpoint.
Also check this example which describes how to create topic, subscribe endpoint, confirm subscription and start to receive notification messages from SNS (uses Java SDK): https://github.com/mfine/AmazonSNSExample
General picture is:
On the publisher side:
create topic and subscribe some endpoint to receive messages. After subscribing endpoint to topic, the endpoint will receive SubscriptionConfirmation message.
start publish to topic so your endpoints will receive notification messages
On the subscriber side (your endpoint should be able to handle at least confirm subscription request and notification messages):
confirm subscription: make HTTP GET request to the "SubscribeURL" URL which comes inside the body of the confirm subscription request. Before you confirm subscription your endpoint will not receive any messages from SNS
receive notification messages and do what you want

Resources