[BUG] Ably.Push.Admin publish does not have a correct types
The generated code in ably.d.ts does not have types, it is using any
https://github.com/ably/ably-js/blob/953563ba4afb07b6f54ca43822915bf8700f4889/ably.d.ts#L3167-L3174
I assume the type should be something like this for the recipient?
type PushRecipient =
| {
deviceId: string;
}
| { clientId: string }
| {
transportType: 'apns' | 'fcm';
deviceToken: string;
};
No idea what to put for the payload there from the code, but from the docs something like
{
title: string
body: string
ttl: 3600
}
Hey @distante,
Thanks for raising, we are looking into this now and come back with response shortly!
Hi @distante ,
Looking at the docs for direct publishing and for REST API docs for push I was able to gather the next expected inputs for recipient and payload fields:
export declare interface PushAdmin {
publish(recipient: RecipientType, payload: PayloadType): Promise<void>;
}
type RecipientType =
| DeviceIdRecipient
| ClientIdRecipient
| ApnsRecipient
| FcmRecipient
| WebRecipient;
// https://ably.com/docs/push/publish#device-id
type DeviceIdRecipient = {
deviceId: string;
};
// https://ably.com/docs/push/publish#client-id
type ClientIdRecipient = {
clientId: string;
};
// https://ably.com/docs/push/publish#recipient and https://ably.com/docs/api/rest-api#post-device-registration
type ApnsRecipient = {
transportType: 'apns';
deviceToken: string;
};
type FcmRecipient = {
transportType: 'fcm';
registrationToken: string;
};
type WebRecipient = {
transportType: 'web';
targetUrl: string;
publicVapidKey: string;
encryptionKey: {
p256dh: string;
auth: string;
};
};
type PayloadType = {
notification: {
title?: string;
body?: string;
icon?: string;
sound?: string;
collapseKey?: string;
ttl?: number; // Required for Web Push on some platforms and browsers like Microsoft Edge (WNS)
};
data?: Record<string, string>;
apns?: {
// optional, extends and overrides parent values from PayloadType when delivering via APNs
// for example, you can override notification field here and set APNs headers https://ably.com/docs/push/publish#apns-headers
};
fcm?: {
// optional, extends and overrides parent values from PayloadType when delivering via FCM
// for example, you can override notification field here
};
web?: {
// optional, extends and overrides parent values from PayloadType when delivering via web
// for example, you can override notification field here
};
};
(notice that payload has an additional notification property where you will add props like title and body as you mentioned in your comment)
We will look into adding correct types for push.admin.publish() parameters. In the meantime I hope the interfaces above will unblock you.
Thanks @VeskeR, this helps me a lot!