How do I add a channelId to my notification?


I’ve written a cloud function to send a cloud message to a specific device.

export const onGroupInvitationCreate = functions.region('europe-west1').firestore.document('users/{userId}/userGroupInvitations/{invitationId}').onCreate(async (handler, context) => {

    const invitation = GroupInvitationModel.fromFirestoreDocumentData(handler);

    const documentList = await userCollection.doc(invitation.receiverId).collection('userDeviceData')

    const futureDocuments = [];

    for(const documentReference of documentList)

    const deviceDatas = (await Promise.all(futureDocuments)).map(deviceData => DeviceDataModel.fromFirestoreDocumentData(deviceData));

    const futureNotifications = [];

    for(const deviceData of deviceDatas)
        const translator = deviceData.language !== 'nl' ? languages.en :;

        const payload: admin.messaging.MessagingPayload = {
            // notification: {
            //     title: `${translator['invitationTitle' as keyof typeof translator]}`,
            //     body: `${invitation.senderDisplayName} ${translator['invitationBody' as keyof typeof translator]} ${invitation.groupDisplayName}`,
            //     clickAction: 'FLUTTER_NOTIFICATION_CLICK',
            // },            
            data: {
                title: `${translator['invitationTitle' as keyof typeof translator]}`,
                body: `${invitation.senderDisplayName} ${translator['invitationBody' as keyof typeof translator]} ${invitation.groupDisplayName}`,
                clickAction: 'FLUTTER_NOTIFICATION_CLICK',
                senderId: invitation.senderId,
                senderDisplayName: invitation.senderDisplayName,
                type: 'invitation',
                sentAt: new Date().toISOString(),

        futureNotifications.push(messaging.sendToDevice(deviceData.cloudMessagingToken, payload));

    await Promise.all(futureNotifications).catch((error) => console.error(`There was an error while notifying receiver ${invitation.receiverId}`, error));

    return Promise.resolve('Status 200');

How would I provide a channelId? I am using the


Which takes a registrationToken, a payload and options. And I noticed that none of those have the propery channelId.

The AndroidConfig does have a property channelId, but I couldn’t find how to use that when I send the notification.

This is what the sendToDevice takes as arguments

  registrationToken: string | string[],
  payload: admin.messaging.MessagingPayload,
  options?: admin.messaging.MessagingOptions
): Promise<admin.messaging.MessagingDevicesResponse>;


You need to pass the android_channel_id property in the notification section of MessagingPayload. See table 2b in for a complete list of all the Android-related options accepted by the legacy FCM APIs.

If you wish to use AndroidConfig, you must first migrate to the new FCM API (i.e. the send() method).

Answered By – Hiranya Jayathilaka

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published