Sending push notification from Angular and Firebase server - firebase

I am able to send Push Notification using Postman. I don't want to use a separate server and send Push Notifications using PHP.
Current using POST method - https://fcm.googleapis.com/fcm/send
As I am using Firestore as database and Firebase as hosting to host my app
How can I send notifications using Firebase server. Below is what I am using via Postman to send a notification at the moment.
{
"to": "my token id",
"data": {
"title": "Push Message",
"message": "This is notification will change tab",
"sound": "default",
"badge": 2,
"page": "offline-storage",
"taskid":156
},
"notification":{
"title": "Push Message",
"message": "This is notification will change tab",
"sound": "default",
"badge": 2,
"page": "offline-storage",
"taskid":156
}
}
Screenshot attached

Related

Sending a notification through Firebase's FCM API Test

I'm currently trying to send a notification using the " Try this API " interface of Firebase.
I filled my Request Body with this :
{
"validateOnly": false,
"message": {
"notification": {
"body": "Body",
"title": "Title"
}
}
}
and the RequestParameters with
projects/myprojectid
I didn't check the Google API Key since my project doesn't have one, but I checked the Google OAuth 2.0.
After executing, I get this error :
{
"error": {
"code": 400,
"message": "Recipient of the message is not set.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message",
"description": "Recipient of the message is not set."
}
]
},
{
"#type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "INVALID_ARGUMENT"
}
]
}
}
After some research, I don't understand what is missing in the request. Are all the parameters mandatory for the request ?
You're not specifying who the message is for, which is what the error message is trying to tell you. You can do by either including a token key with one of more device tokens, or a topic or condition key in the JSON.
Also see the Firebase documentation on building requests to send a message for more information and examples of each of these.

how can I send fcm using user segment

now I'm testing http request using POSTMAN
**"to": "/topics/all", ---> ?? how can i write this line??**
"priority": "high",
"notification": {
"title": "テスト Title",
"body": "テスト Body"
},
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK"
}
I checked status 200 ok
when I send message with firebase web page, it works well
but without firebase cloud message service, it doesn't work
In firebase cloud message service, the targeting condition is
I'm suppose that if i can write targeting condition in http format, I can send message to my app
help me
What you are looking for is key "topic"
{
"topic": "all",
"notification":{
"title": "テスト Title",
"body": "テスト Body"
},
"data":{
"click_action": "FLUTTER_NOTIFICATION_CLICK"
}
}

Twilio Push Notifications: Get received status when sending using Passthrough API

I'm using the Twilio Notify Service to send push notifications to APN and FCM. We would like to switch to the passthrough API for situations where we send to a large number of users at once. Howerver, I'm not getting the to_binding field in the response, so have no idea how many succeeded or failed. When sending using identity, we get an array of identities.
Here is what we are sending:
twilio_client.notify.v1.services(ENV.fetch('TWILIO_NOTIFY_SERVICE')).notifications.create(
to_binding: params[:users],
body: params[:body],
title: params[:title],
data: {data: #data},
fcm: {
data: {
title: params[:title],
body: params[:body]
}
}
)
I get notifications on the devices, but this is what I get back:
{"body": "stuff", "sound": null, "sms": null, "alexa": null, "facebook_messenger": null, "tags": [], "title": "My Title", "segments": [], "ttl": 545435, "gcm": null, "account_sid": "account_id", "priority": "high", "apn": null, "data": {"data": {"a_thing": 995, "type": "My Type", "id": 4344}}, "sid": "myid", "action": null, "date_created": "2019-11-05T15:25:27Z", "service_sid": "service_id", "identities": [], "fcm": {"data": {"body": "stuff", "title": "My Title"}}}
in the example from the docs (https://www.twilio.com/docs/notify/api/notification-resource?code-sample=code-send-a-notification-to-bindings-in-the-request-1&code-language=Ruby&code-sdk-version=5.x), it looks like a toBindings field should come back.
Is there a way to get this working, or some way to fetch received receipt data after with the notification id?
It looks like as of now, this feature is not implemented, and is mentioned in their coming soon section along with iOS/Android SDKs

Dialogflow V2 Messenger Integration with Multiple Messages

I am trying to send to multiple messages within one Webhook call to Dialogflow, which shall be passed to Messenger. Right now my Webhook responds with a malfunctioning JSON body:
{
'fulfillmentText': "Text",
'fulfillmentMessages': [{
"platform": "facebook",
"text": [{
"text": "Text"
}]
}],
'source': "facebook"
}
When I test the Webhook via Messenger I see the is typing symbol, but never receive the Text message. While testing the same Webhook from the Dialogflow Console I get
Webhook execution successful
returned. I guess I am missing some JSON fields to tell Dialogflow in which format it has to send the JSON two the Messenger API. Anybody having any clues on how to solve this issue?
Edit:
My latest not working trial...
{
"fulfillmentText": "Hola!",
"fulfillmentMessages": [
{
"text": {
"text": [
"Title: this is a title"
]
},
"platform": "FACEBOOK"
},
{
"text": {
"text": [
"Title: this is a title"
]
},
"platform": "FACEBOOK"
}
]
}
If you're only sending text you only need to provide a string to the fulfillmentText and don't have to provide the fulfillmentMessages attribute.
If you do provide a fulfillmentMessages attribute with the target platform Dialogflow will send your payload to Facebook. In this case, where the payload is invalid, no message will actually be surfaced in Facebook. remove the fulfillmentMessages attribute of the response JSON and your bot should respond.
If you'd like to add a card to your response you can send the following response:
{
"fulfillmentMessages": [
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji 📱.",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
}
]
}
EDIT: If you want to send multiple messages you can do so by sending a response like this (this JSON will send two identical cards but you can change the message type (card/text/etc) based on this documentation):
{
"fulfillmentMessages": [
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji 📱.",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
},
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji 📱.",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
}
]
}
I mailed the Dialogflow support about this issue and it turns out that it is currently not possible to send multiple messages from a webhook.
Hi,
At this point, it's not possible to send sequential messages directly
from webhook. However, if you are using one of our one-click
integrations that support rich messages, you can invoke intents in
which multiple messages are defined from webhook through an event as
described at
https://dialogflow.com/docs/events#invoking_event_from_webhook.
Let me know if you have any questions.
Regards, Ankita from Dialogflow

Firebase Android - send notification messages using POST requests without an App Server, but directly from the Android app

Is there a way to send push notification directly from an Android app by making POST requests directly to https://fcm.googleapis.com/fcm/send ? If so, can you please provide an example.
If you can read JavaScript, check the simple-fcm-client example on react-native-fcm. Specifficaly, the FirebaseClient.js file
I'll post the code here for completeness, but you need to replace token with the destined device's registered token and FirebaseConstants.KEY with your API Web key from your Firebase console.
const API_URL = "https://fcm.googleapis.com/fcm/send";
class FirebaseClient {
constructor() {
this.sendData = this.sendData.bind(this);
this.sendNotification = this.sendNotification.bind(this);
this.sendNotificationWithData = this.sendNotificationWithData.bind(this);
}
sendNotification(token) {
let body = {
"to": token,
"notification":{
"title": "Simple FCM Client",
"body": "This is a notification with only NOTIFICATION.",
"sound": "default",
"click_action": "fcm.ACTION.HELLO"
},
"priority": 10
}
this._send(JSON.stringify(body), "notification");
}
sendData(token) {
let body = {
"to": token,
"data":{
"title": "Simple FCM Client",
"body": "This is a notification with only DATA.",
"sound": "default",
"click_action": "fcm.ACTION.HELLO",
"remote": true
},
"priority": "normal"
}
this._send(JSON.stringify(body), "data");
}
sendNotificationWithData(token) {
let body = {
"to": token,
"notification":{
"title": "Simple FCM Client",
"body": "This is a notification with NOTIFICATION and DATA (NOTIF).",
"sound": "default",
"click_action": "fcm.ACTION.HELLO"
},
"data":{
"title": "Simple FCM Client",
"body": "This is a notification with NOTIFICATION and DATA (DATA)",
"click_action": "fcm.ACTION.HELLO",
"remote": true
},
"priority": "high"
}
this._send(JSON.stringify(body), "notification-data");
}
_send(body, type) {
let headers = new Headers({
"Content-Type": "application/json",
"Content-Length": parseInt(body.length),
"Authorization": "key=" + FirebaseConstants.KEY
});
fetch(API_URL, { method: "POST", headers, body })
.then(response => console.log("Send " + type + " response", response))
.catch(error => console.log("Error sending " + type, error));
}
}

Resources