首页 > 解决方案 > 使用 typrescript 和 if 语句的云函数

问题描述

您好,我是云功能的新手,我想问一下为什么在一个 if 语句中获得多个主题是我的云功能:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();

const fcm = admin.messaging();

export const sendToTopic = functions.firestore
  .document("Doctor2019/{documentId}")
  .onCreate(async snapshot => {

    const payload: admin.messaging.MessagingPayload = {
      notification: {
        title: 'NEW POST!',
        body: `Click here to see New Post`,
        icon: 'your-icon-url',
        click_action: 'FLUTTER_NOTIFICATION_CLICK'
      }
    };

    return fcm.sendToTopic('Doctor2019', payload);
  });


问题是我有不止一个主题我想做的是检查其他集合上文档的创建并基于此发送通知,我真的不知道该怎么做,有什么帮助吗?

标签: firebasefluttergoogle-cloud-firestoregoogle-cloud-functionsfirebase-cloud-messaging

解决方案


我看到您想将消息发送到 FCM 上与不同文档创建相关的不同主题。

您不能使用一个函数来实现这一点,因为该函数与特定集合上的文档创建相关联。您需要做的是为不同的集合创建不同的功能。


推荐阅读