Firebase messageId - firebase

I'm sending push notifications by topic using firebase. The response I get looks like this { messageId: 'mymessageid'}
I can't find anywhere I can use this ID to look up information on the notification I sent. I've been through the docs for both client and server side firebase libraries.
Is there a way to use the messageId returned from a send to topic to look up information about the notification's status?

Related

Firebase cloud function send notification to all users

I am trying to send a notification to all users of my app whenever there is a write on the database.
Here is the code that I have so far.
export const newUserAdded = functions.database
.ref('1_0_0/updateDate/date')
.onWrite((event)=>{
//send notfigication to all
admin.messaging().sendToCondition()
})
As you can see whenever there is a write to the date key the function will trigger.
But note here that I do not have device token of the user as I want to send a notification to all users. I was not able to find any method do so.
Kindly do let me know how can I achieve this.
Thanks
You can use topic messaging. Arrange for all your client apps to subscribe to a dedicated, named topic for broadcasting to all app installations, then send your message to that topic.

gmail API watch webhook: how to get the user-id

We need to use push notifications for many users, using watch Gmail API call.
The watch response we should get on the webhook does not contain any information about the user for which the webhook has been called.
The problem is that according to Users.history: list
I cannot get messages without user-id.
How am I supposed to get user-id from the watch webhook?
OR
Is it possible to call something similar to "Users.history: list" without the need to have user-id?
Thanks for your support,
Adrien
Edit from info in link in comment
If you check the Push Notifications you will see that the response from the server contains a data field.
// This is the actual notification data, as base64url-encoded JSON.
data: "eyJlbWFpbEFkZHJlc3MiOiAidXNlckBleGFtcGxlLmNvbSIsICJoaXN0b3J5SWQiOiAiMTIzNDU2Nzg5MCJ9",
The HTTP POST body is JSON and the actual Gmail notification payload is in the message.data field. That message.data field is a base64url-encoded string that decodes to a JSON object containing the email address and the new mailbox history ID for the user:
{"emailAddress": "user#example.com", "historyId": "9876543210"}
Data contains the email address of the user.
Note I don't have the power to test this I am just reading the documentation. I don't have a server set up to retrieve these notifications.
user-id is your email, which is used to subscribe push notification

Can I send push notification using custom_ids not FCM registration-id from my server?

If we want to send message to different device we need to specify their registration_ids in https://fcm.googleapis.com/fcm/send. Is there some API where we can register users unique user_id and send messages using that user_id?
My use case is, I am using Parse for notification and if there are 5 people in a chat, we send notification to those 5 people if there is some activity in the chat. We are already storing the user_id in our database. Now if there is some API where I can specify the registration_ids and user_id. And then later just use user_id instead of storing registration_ids in our database.
If you plan on using FCM for the push notification, short answer is No.
What is required in FCM for you to send to a single or multiple device(s) is/are the registration token(s) and by using the corresponding parameters to, registration_ids in the payload to send it to them.
Other details is pretty much covered by #FrankvanPuffelen's comment.

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

Push Notifications through Firebase

Yesterday Google has announced a new set of tools for Firebase, one of them was Notifications the ability to send notifications from server to devices which are using my app.
But can we now notify users when they receive a new message?
And if not, is there a way around to achieve this?
Looking at the documentation, this doesn't seem currently possible automatically. Here is a possible way to accomplish it "manually" with another server:
Subscribe a user to it's own user ID
In android
FirebaseMessaging.getInstance().subscribeToTopic("InsertUserIDHere");
In IOS
[[FIRMessaging messaging] subscribeToTopic:#"/topics/InsertUserIDHere"];
Setup an outside server that checks every sent messages. When a message is sent, the server should create a notification that includes the recipient's user ID as the topic.
Look here for more info.
You can send messages to group of users (targeting a specific "topic") or to a single device (targeting a Firebase Cloud Messaging token).
To subscribe a device to a topic use:
FirebaseMessaging.getInstance().subscribeToTopic("topicName");
To obtain the device token use (*1) :
FirebaseInstanceId.getInstance().getToken();
Then you can use the Firebase Notificaitons web console, or the FCM server API if you want to send messages from your server.
See: https://firebase.google.com/docs/cloud-messaging/downstream#sending_topic_messages_from_the_server
Notes:
[1] getToken() can return null if the token is not yet available.
You can use the callback onTokenRefresh() to be notified when the token is available and when the token is rotated.
See: https://firebase.google.com/docs/cloud-messaging/android/client#sample-register

Resources