I am trying to migrate FCM from legacy API to HTTP V1 API. A sample “working code before” and after the modification is as follows:
Before:
const payload =
{
data:
{
title: "Alert: New Query",
body: "You have received a new order query",
icon: "default"
}
}
const options = {
priority: "high"
}
await admin.messaging().sendToDevice(pharmToken, payload, options)
After:
const message ={
name: 'Alert',
notification: {
title: 'Alert: New Query!'
},
data:
{
title: "Alert: New Query",
body: "You have received a new order query",
icon: "default"
},
android: {
notification: {
title: "Alert: New Query",
body: "You have received a new order query",
icon: "default"
},
priority: "high",
},
token:pharmToken,
}
await admin.messaging().send(message)
But Typescript is throwing an error at “message” within await admin.messaging().send(message)
It says:
Argument of type ‘{ name: string; notification: { title: string; }; data: { title: string; body: string; icon: string; }; android: { notification: { title: string; body: string; icon: string; sound: string; }; priority: string; }; token: any; }’ is not assignable to parameter of type ‘Message’.
Type ‘{ name: string; notification: { title: string; }; data: { title: string; body: string; icon: string; }; android: { notification: { title: string; body: string; icon: string; sound: string; }; priority: string; }; token: any; }’ is not assignable to type ‘TokenMessage’.
The types of ‘android.priority’ are incompatible between these types.
Type ‘string’ is not assignable to type ‘”high” | “normal” | undefined’
I am using admin-sdk