i have this payload below that send push from firebase function. the payload send notification successful to Android. now i am confused about the iOS.
my Question is that:
will this also send to iOs because i can see that there is no alert in the payload in apsn.
i fellow the documentation in this site which they did not give ios payload.
when i make a research on iOs payload i can see something like this
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
but in the documentation i cant found where they give alert
exports.chatFunctions = functions.firestore.document("chat/{chatId}/Messages/{messagesId}").onCreate(async (snapshot, context) => {
if (!snapshot.exists) {
console.log('No Device');
}
const chatDatas = snapshot.data();
const messageTo = chatDatas['idTo'];
const deviceTokenuUser1 = await admin.firestore().collection('users').doc(messageTo).get();
const user1name = deviceTokenuUser1.data()['name'];
const user1Url = deviceTokenuUser1.data()['profilePictureUrl'];
let payload = {
notification: {
title: `${user1name}`,
body: `${chatDatas['content']}`,
},
data: {
key: 'chat',
id: `${messageTo}`,
click_action: "FLUTTER_NOTIFICATION_CLICK"
},
android: {
priority: "high",
},
apns: {
payload: {
aps: {
contentAvailable: true,
},
},
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
},
token: deviceTokenuUser1.data()['tokens'],
};
try {
await admin.messaging().send(payload);
console.log("Firebase chat Messaging Successfully");
} catch (err) {
console.log("error from chat messaging " + err);
}
Related
I am trying to update live activities using remote push notifications.
I am creating a live activity like this:
do{
let activity = try Activity<LiveMatchesAttributes>.request(attributes: attributes, contentState: state, pushType: .token)
print("Activity Added Successfully. id: \(activity.id)")
Task {
for await data in activity.pushTokenUpdates {
let myToken = data.map {String(format: "%02x", $0)}.joined()
print("pushToken", myToken)
}
}
}catch{
print(error.localizedDescription)
}
The live activity shows up in the notifications center and the pushToken can also be received.
Now I am trying to update the live activity using remote notifications. The code for that looks like this:
exports.updateLiveActivities = functions.https.onRequest((req, res) => {
const fcmToken = "fcmToken"
const apns = {
headers: {
"apns_push_type" : "liveactivity",
"apns_topic" : "bundle_id.push-type.liveactivity",
},
"payload": {
"aps": {
"timestamp" : Date.now(),
"event": "update",
"content-state": {
"event": "start"
},
"alert": {
"title": "Race Update",
"body": "Tony Stark is now leading the race!"
}
},
}
}
const message = {
token: fcmToken,
apns: apns
}
admin.messaging().send(message).then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
res.send("ok")
// return res.send("ok");
}).catch((error) => {
console.log(error)
return res.send(error.code);
});
});
Sending the remote notification works because the "alert" is appearing on my phone but the live activity is not getting updated. Any ideas where to insert the received "pushToken" for the live activity?
i am using push notification with local notification.. i have to set channel id in my payload..
here is my payload
i am not sure if this is payload for both andriod and ios. please help me out with correct payload.
thanks
exports.chatFunctions = functions.firestore.document("chat/{chatId}/Messages/{messagesId}").onCreate(async (snapshot, context) => {
if (!snapshot.exists) {
console.log('No Device');
}
const chatDatas = snapshot.data();
const messageTo = chatDatas['idTo'];
const deviceTokenuUser1 = await admin.firestore().collection('users').doc(messageTo).get();
const user1name = deviceTokenuUser1.data()['name'];
const user1Url = deviceTokenuUser1.data()['profilePictureUrl'];
let payload = {
notification: {
title: `${user1name}`,
body: `${chatDatas['content']}`,
},
data: {
key: 'chat',
id: `${messageTo}`,
click_action: "FLUTTER_NOTIFICATION_CLICK"
},
android: {
priority: "high",
},
apns: {
payload: {
aps: {
contentAvailable: true,
},
},
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
},
token: deviceTokenuUser1.data()['tokens'],
};
try {
await admin.messaging().send(payload);
console.log("Firebase chat Messaging Successfully");
} catch (err) {
console.log("error from chat messaging " + err);
}
You can add channel id like this:
let payload = {
// ...
android: {
priority: "high",
notification: {
channelId: "yourchannelid"
}
}
// ...
}
I'm using aws-sdk in my service to send emails. I'm getting below exception to a code which was working fine before.
const aws = require('aws-sdk');
var params = {
Destination: {
ToAddresses: [
'checkMail#gmail.com'
]
},
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: "HTML_FORMAT_BODY"
},
Text: {
Charset: "UTF-8",
Data: "this is sample"
}
},
Subject: {
Charset: 'UTF-8',
Data: 'Test email'
}
},
Source: 'AWS Services<awsEmails#awsService.com>'
ReplyToAddresses: [
'AwsServices<noreply#awsServices.com>'
],
};
// Create the promise and SES service object
var emailPromise = new aws.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();
// Handle promise's fulfilled/rejected states
emailPromise.then(
function(data) {
//my logic on success goes here
}).catch(
function(err) {
//my logic on error goes here
});
I have tried using different API calls for email from AWS but all returns the same error.
Avoid require ALL aws-sdk if it's just to use a single service. For using SES, you can yarn add #aws-sdk/client-ses and then use it const { SESClient, SendEmailCommand } = require("#aws-sdk/client-ses");
I show you here a full exemple of sending email with SES in a nodeJS lambda function:
const {
SESClient,
SendEmailCommand,
} = require("#aws-sdk/client-ses");
const REGION = "eu-west-3"; // Use you AWS region
const ses = new SESClient({ region: REGION });
exports.handler = async function (event) {
const path = event.path;
if (path === "/send-email") {
const peopleAmount = 12;
const params = {
Source: "John Wick <john.wick#killer.com>",
Destination: {
ToAddresses: ["adresse1#test.com"],
},
Message: {
Body: {
Html: {
Data: `<span>This email is about <b>${peopleAmount}</b> people.</span>`,
},
},
Subject: {
Data: "Email Title",
},
},
};
try {
const data = await ses.send(new SendEmailCommand(params));
return {
statusCode: 200,
body: peopleAmount,
};
} catch (e) {
console.error(e, e.stack);
return {
statusCode: 400,
body: "Sending failed",
};
}
}
}
I hope it helps, here is documentation to use SES email template.
Am trying to update the json data through an api call.
I was able to GET the data without any issues, as am not passing any Options in the request.
For UPDATE,
//saga.js
export function* BlurideaTitler(opt) {
const id = opt.id; // 4
const updatedTitle = opt.newTitle; // "title changed"
let options = {
crossDomain: true,
method: 'PUT',
json: true,
headers: {'Content-Type': 'application/json'},
body: {
title: updatedTitle
}
};
const requestURL = `http://localhost:3000/ideas/${id}`;
try {
yield call(request, requestURL, options);
} catch (err) {
console.log(err);
}
}
// request.js
export default function request(url, options) {
return fetch(url, options)
.then(checkStatus)
.then(parseJSON);
}
//db.json
JSON am trying to update.,
{
"ideas": [
{
"id": 4,
"title": "My fourth Idea",
"body": "Description of my fourth idea",
"created_date": "14-Apr-2019"
}
]
}
This is supposed to update the value of title. But it throws error'Bad request' . Can someone please let me know what am missing here.
I am using ionic.io to send push to my app. I have following body
{"tokens":["DeviceToken"],
"profile":"Profile",
"notification":{ "payload": {
"type": "loadCategories"
},
"ios": {
"content_available": 1
},
"android": {
"content_available": "1"
}}}
Type script code.
var push = Push.init({
android: {
senderID: "ID"
},
ios: {
alert: "true",
badge: true,
sound: 'false'
},
windows: {}
});
if((<any>push).error) {
console.log((<any>push).error);
return;
};
push.on('registration', (data)=>{
console.log(data.registrationId);
this.pushToken = data.registrationId;
this.updateToken();
});
push.on("notification", (data)=>{
console.log(data);
// if(data.additionalData.payload && data.additionalData.payload.type == 'categoryEvent') {
// console.log("at date")
// }
});
push.on('error', function(e) {
console.log(e.message);
});
Idea is that I need to send push to user and load data from the server. But problem is that if app is in background then notification event is not fired. It works only if app is active. But as soon as i understand from documentation it should work.
Known issue that has been addressed with setting content_available = 1. See https://github.com/phonegap/phonegap-plugin-push/issues/93 for more.