gpt4 book ai didi

node.js - Firebase 云消息传递 android 优先级属性

转载 作者:行者123 更新时间:2023-12-02 19:39:50 26 4
gpt4 key购买 nike

我正在尝试将通知优先级设置为 HIGH,如文档中所述 here和特定参数定义here .但是,当我在我的云函数中设置此属性时,我在尝试部署时收到以下错误:

src/index.ts:107:35 - error TS2345: Argument of type '{ tokens: string[]; notification: { title: string; body: any; }; data: { title: any; subtitle: any; body: any; id: any; }; android: { notification: { icon: string; channel_id: string; tag: any; }; priority: string; }; }' is not assignable to parameter of type 'MulticastMessage'.
The types of 'android.priority' are incompatible between these types.
Type 'string' is not assignable to type '"normal" | "high" | undefined'.

107 admin.messaging().sendMulticast(message)
~~~~~~~

我明白这意味着我不应该输入字符串。但根据文档,这是预期的类型。不仅如此,我还很困惑它在引号 '"normal | "high"| undefined' 中指的是什么类型。那是什么类型?

这是正在设置的完整消息容器:

const message = {
tokens: tokens,
notification: {
title: snapshot.data().sender_username + " - " + snapshot.data().group_name,
body: snapshot.data().content
},
data: {
title: snapshot.data().group_name,
subtitle: snapshot.data().sender_username,
body: snapshot.data().content,
id: message_topic
},
android: {
notification: {
icon: 'add_circle_outline',
channel_id: 'exampleChannelId',
tag: message_topic

},
priority: "high" // <-- This is where the error is thrown
}
};

最佳答案

由于类型不匹配,IDE 不满意。

一个解决方案是显式输入 android 配置:

import * as admin from 'firebase-admin';

const androidConfig: admin.messaging.AndroidConfig = {
priority: 'high',
...,
};

const message = {
...,
android: androidConfig,
};

这很好,因为您可以看到可以设置的其他配置选项。关于这一点,您还可以显式键入整个消息,在本例中为 admin.messaging.MulticastMessage

关于node.js - Firebase 云消息传递 android 优先级属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60425682/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com