Web 应用程序未收到 Firebase 云消息传递通知
Firebase Cloud Messaging Notification not received in web app
我正在使用 FCM 进行通知。 FCM 在从 Firebase 数据库创建数据时被触发。我收到了第一条消息。在那之后,其他连续的消息都没有收到。我在本地环境中 运行 这个。问题是由于以下消息“未配置计费帐户。无法访问外部网络且配额受到严格限制。配置计费帐户以删除这些限制”或任何其他问题。我是否需要为接收消息制定计费计划?在测试环境中工作,这就是不转向计费计划的原因。如果问题与计费计划无关,有人可以指出代码的任何其他问题。
Firebase 函数日志
6:22:52.133 PM
sendFollowerNotification
Function execution started
6:22:52.133 PM
sendFollowerNotification
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
6:22:52.143 PM
sendFollowerNotification
Function execution took 10 ms, finished with status: 'ok'
6:22:52.401 PM
sendFollowerNotification
1 messages were sent successfully
节点js代码
exports.sendFollowerNotification = functions.database.ref('/notification/message/{gId}/{pId}')
.onCreate(async (change, context) => {
//console.log('Group id:', context.params.gId," Push ID:",context.params.pId, "Change",change);
const notificationData = change.val();
var topic = notificationData.topic;
var title = notificationData.title;
var body = notificationData.body;
var registrationTokens = notificationData.tokens;
const message = {
notification: {
title: title,
body: body
},
tokens: registrationTokens,
};
admin.messaging().sendMulticast(message)
.then((response) => {
// Response is a message ID string.
console.log(response.successCount + ' messages were sent successfully');
})
.catch((error) => {
console.log('Error sending message:', error);
});
});
我认为这可能会回答您的问题:Why will I need a billing account to use Node.js 10 or later for Cloud Functions for Firebase?:
Because of updates to its underlying architecture planned for August 17, 2020, Cloud Functions for Firebase will rely on some additional paid Google services: Cloud Build, Container Registry, and Cloud Storage. These architecture updates will apply for functions deployed to the Node.js 10 runtime. Usage of these services will be billed in addition to existing pricing.
在新的架构中,Cloud Build支持函数的部署。您只需为构建函数的运行时容器所需的计算时间付费。
另一方面,服务 Firebase Clud Messaging
本身是免费的:
Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.
鉴于您在 CF 中使用 Node,平台需要您提供一个结算帐户。
该消息并不表示错误。这只是一个警告,让您知道如果您的项目不在付款计划中,出站网络将不起作用。 FCM 消息传递不属于此类 - 它应该有效。
问题是您的代码没有 return 在所有异步工作完成后解决的承诺。现在,它 return 什么都没有,函数在消息发送前立即终止。请阅读并理解关于此的documentation。
至少,您需要 return 承诺链让 Cloud Functions 知道消息何时发送,并且可以安全终止。
return admin.messaging().sendMulticast(message)
.then((response) => {
// Response is a message ID string.
console.log(response.successCount + ' messages were sent successfully');
})
.catch((error) => {
console.log('Error sending message:', error);
});
注意上面的 return 关键字。
如果邮件仍然没有发送出去,那么这里还有其他一些我们看不到的问题。您可能没有正确处理您的设备令牌。
我正在使用 FCM 进行通知。 FCM 在从 Firebase 数据库创建数据时被触发。我收到了第一条消息。在那之后,其他连续的消息都没有收到。我在本地环境中 运行 这个。问题是由于以下消息“未配置计费帐户。无法访问外部网络且配额受到严格限制。配置计费帐户以删除这些限制”或任何其他问题。我是否需要为接收消息制定计费计划?在测试环境中工作,这就是不转向计费计划的原因。如果问题与计费计划无关,有人可以指出代码的任何其他问题。
Firebase 函数日志
6:22:52.133 PM
sendFollowerNotification
Function execution started
6:22:52.133 PM
sendFollowerNotification
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
6:22:52.143 PM
sendFollowerNotification
Function execution took 10 ms, finished with status: 'ok'
6:22:52.401 PM
sendFollowerNotification
1 messages were sent successfully
节点js代码
exports.sendFollowerNotification = functions.database.ref('/notification/message/{gId}/{pId}')
.onCreate(async (change, context) => {
//console.log('Group id:', context.params.gId," Push ID:",context.params.pId, "Change",change);
const notificationData = change.val();
var topic = notificationData.topic;
var title = notificationData.title;
var body = notificationData.body;
var registrationTokens = notificationData.tokens;
const message = {
notification: {
title: title,
body: body
},
tokens: registrationTokens,
};
admin.messaging().sendMulticast(message)
.then((response) => {
// Response is a message ID string.
console.log(response.successCount + ' messages were sent successfully');
})
.catch((error) => {
console.log('Error sending message:', error);
});
});
我认为这可能会回答您的问题:Why will I need a billing account to use Node.js 10 or later for Cloud Functions for Firebase?:
Because of updates to its underlying architecture planned for August 17, 2020, Cloud Functions for Firebase will rely on some additional paid Google services: Cloud Build, Container Registry, and Cloud Storage. These architecture updates will apply for functions deployed to the Node.js 10 runtime. Usage of these services will be billed in addition to existing pricing.
在新的架构中,Cloud Build支持函数的部署。您只需为构建函数的运行时容器所需的计算时间付费。
另一方面,服务 Firebase Clud Messaging
本身是免费的:
Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.
鉴于您在 CF 中使用 Node,平台需要您提供一个结算帐户。
该消息并不表示错误。这只是一个警告,让您知道如果您的项目不在付款计划中,出站网络将不起作用。 FCM 消息传递不属于此类 - 它应该有效。
问题是您的代码没有 return 在所有异步工作完成后解决的承诺。现在,它 return 什么都没有,函数在消息发送前立即终止。请阅读并理解关于此的documentation。
至少,您需要 return 承诺链让 Cloud Functions 知道消息何时发送,并且可以安全终止。
return admin.messaging().sendMulticast(message)
.then((response) => {
// Response is a message ID string.
console.log(response.successCount + ' messages were sent successfully');
})
.catch((error) => {
console.log('Error sending message:', error);
});
注意上面的 return 关键字。
如果邮件仍然没有发送出去,那么这里还有其他一些我们看不到的问题。您可能没有正确处理您的设备令牌。