【问题标题】:Send Notification via Firebase to everyone in a topic but the sender [duplicate]通过 Firebase 向主题中的所有人发送通知,但发件人 [重复]
【发布时间】:2018-05-08 02:14:34
【问题描述】:

如何向订阅主题但消息发送者以外的所有人发送通知?很抱歉JS代码真的很蹩脚我保证我会改进它,这个代码将推送通知发送给当前订阅的每个人包括消息发送者,我只需要停止发送发送者,谢谢

let functions = require('firebase-functions');
var admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase)

exports.newMessage = functions.database.ref('groups/{groupId}/messages/{messageId}')
	.onWrite(event => {
		const message = event.data.val()
		const groupId = event.params.groupId

		sendNotification(message, groupId)
	})


	function sendNotification(message, groupdIdTopic) {
		let title = message.placeName
		let subtitle = message.content

		let payload = {
			notification: {
				title: title,
				body: subtitle,
				sound: 'default',
				badge: '1',
				mutable_content: 'true'
			},
			data : {
	      		placeId : groupdIdTopic,
	      		userSenderId : message.senderId
	    	}
		}

		var options = {
	      priority: "high",
	      timeToLive: 60 * 60 * 24,
	      mutable_content : true,
	      content_available : true,
	      category : 'reminder'
	    }


		admin.messaging().sendToTopic(groupdIdTopic, payload, options)
	}

【问题讨论】:

  • 客户端应用是网页版还是移动版(Android/iOS)?
  • iOS,你把它标记为重复,所以请把原版发给我

标签: javascript firebase firebase-cloud-messaging google-cloud-functions


【解决方案1】:

消息将发送到订阅该主题的所有设备。没有办法从主题中排除设备,除非它在消息发送之前取消订阅。

似乎您想在消息中包含一些值,发件人可以使用该值来识别消息来自自身,然后使用它来选择忽略整个消息。

除此之外,您的函数不会返回一个表示它何时发送消息的承诺。消息完全有可能永远不会发送,因为 Cloud Functions 可能会在发送消息之前对其进行清理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 2021-10-10
    • 1970-01-01
    相关资源
    最近更新 更多