Ami*_*min 3 node.js firebase-cloud-messaging firebase-admin
我正在尝试将通知优先级设置为,如此处HIGH文档中所述和此处定义的特定参数。但是,当我在云函数中设置此属性时,尝试部署时出现以下错误:
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)
~~~~~~~
Run Code Online (Sandbox Code Playgroud)
我明白这意味着我不应该输入字符串。但根据文档,这是预期的类型。不仅如此,我对引号中所指的类型感到非常困惑'"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
}
};
Run Code Online (Sandbox Code Playgroud)
小智 6
IDE 由于感知到类型不匹配而不满意。
解决方案是显式键入 android 配置:
import * as admin from 'firebase-admin';
const androidConfig: admin.messaging.AndroidConfig = {
priority: 'high',
...,
};
const message = {
...,
android: androidConfig,
};
Run Code Online (Sandbox Code Playgroud)
这很好,因为您可以看到可以设置哪些其他配置选项。在这一点上,您还可以明确键入整个消息,在这种情况下,这将是admin.messaging.MulticastMessage
| 归档时间: |
|
| 查看次数: |
3952 次 |
| 最近记录: |