首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Firestore的Firebase云函数未触发

Firestore的Firebase云函数未触发
EN

Stack Overflow用户
提问于 2018-05-07 09:51:02
回答 3查看 4.4K关注 0票数 2

无法获取Firebase Cloud Functions以在我的集合的onWrite上触发Firestore。正在尝试为聊天应用设置设备到设备推送通知。功能已部署且按需付费计划,但是文档中的更改、更新或“聊天”集合中的创建不会触发。Firebase云消息应该发送推送并写入日志。这两种情况都没有发生。Push正在与其他资源协同工作。

感谢你的帮助,希望设备到设备的推送通知更容易,计划是观看聊天文档并在更新或创建新对话时触发推送通知。对其他想法持开放态度。谢谢

代码语言:javascript
复制
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.sendNotification = functions.firestore
  .document('chats/{chatID}')
  .onWrite((data, context) => {
    // Get an object representing the document
    console.log('chat triggered');
    // perform desired operations ...

    // See documentation on defining a message payload.
    var message = {
      notification: {
        title: 'Hello World!',
        body: 'Hello World!'
      },
      topic: context.params.chatID
    };

    // Send a message to devices subscribed to the provided topic.
    return admin.messaging().send(message)
      .then((response) => {
        // Response is a message ID string.
        console.log('Successfully sent message:', response);
        return true
      })
      .catch((error) => {
        console.log('Error sending message:', error);
      });

  });

更新:我使用的是“firebase函数”:"^1.0.1“

更新:更新了代码,以反映我们当前部署的内容,但仍然不起作用。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50206137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档