Using an interpolated string as the title for Firebase Cloud Functions and Typescript: A beginner's guide

I need help with my cloud function to send notifications to a topic. My current setup uses an interpolated string for the topic:

"topic": `Group: ${groupID}`,

Unfortunately, every time the function is triggered, I encounter an error message: malformed topic name

export const groupMessageReceived = functions.firestore
    .document("Groups/{groupID}/Chat/{message}").onCreate((create, context) => {
      const messageDoc = create.data();
      const groupID = context.params.groupID;
      console.log(`Group: ${groupID}`);
      // const topicName = "Group: " + groupID;
      // sending message to the person who is in the group
      const message = {
        "notification": {
          "title": groupID,
          "body": messageDoc.senderName + ": " + messageDoc.messageContent,
        },
        "topic": `Group: ${groupID}`,
      };

      admin.messaging().send(message)
          .then((response) => {
            // Response is a message ID string.
            console.log("Successfully sent message:", response);
          })
          .catch((error) => {
            console.log("Error sending message:", error);
          });
    });

I'm stuck on this issue and haven't been able to find a solution online. Any insight or suggestions would be greatly appreciated. Feel free to ask for more code if needed! Thank you.

Answer №1

Upon reviewing the error message, it appears that you may want to verify the topic name and ensure it complies with the requirements outlined in the Firebase documentation:

Developers have the flexibility to select any topic name that adheres to the regular expression:

"/topics/[a-zA-Z0-9-_.~%]+"
.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Extensions for MPEG4 streams in CMVideoFormatDescription

While I've successfully managed to decode and play H264 videos, I'm encountering difficulties when it comes to MPEG4 videos. Which CMVideoFormatDescription extensions are required? When attempting to create a VTDecompressionSession, I receive a ...

What is the best method for displaying locations such as "national parks" on iOS using Google Maps SDK?

Currently, I am working with xcode 6.4, Swift, and iOS8 in order to display a map using the Google Maps SDK. The objective is to showcase all results that Google provides when searching for "national park" on Google Maps. My progress so far includes: Ge ...

Using React with Typescript: Can the parent component access data fetched from a nested child component?

Can I access data retrieved from a child component (using a graphql query) in a parent component? For example, how can I use the data fetched by React-component-4 in React-component-1? Is there a way to do this or do I have to duplicate the data fetching ...

Static library for push registration and receiver methods

Looking to develop a static library using Objective-C that includes Push registration and receiver methods. By replicating the Appdelegate functionality, I aim to reduce coding efforts in various apps. Is it feasible to integrate push notifications within ...

Unable to open Bootstrap modal using jQuery within a TypeScript class in AngularJS2 (rc5)

I'm in the process of developing an angular2(rc-5) app using typescript. I recently created a loader component with the intention of opening a modal using jQuery within a typescript class function. However, I'm running into issues where it can&ap ...

The animation in ThreeJs encounters context issues within Angular 2

I am trying to incorporate ThreeJs into my Angular 2 project. I have successfully rendered a scene with a simple cube, but I ran into an issue when using the animate() function. Here is the code snippet: import { OnInit, Component } from '@angular/co ...

What's the most efficient way to define the type of an object in TypeScript when one of its properties shares the same name as the type itself?

I'm currently working on processing an event payload where the event field is a string, and the content of data depends on the value of the event field. While I have come up with a representation that functions correctly, I can't help but feel th ...

Having trouble linking an object with an outlet automatically in Xcode

Having trouble connecting an object to its outlet as the related file is not automatically found when opening assistant editor. Why does the NSObject file always appear instead? https://i.sstatic.net/EMskv.png ...

Issue encountered when utilizing TypeORM within NestJS: Unable to import Entity Repository

Issue with EntityRepository Import Despite having @nestjs/typeorm installed, VS Code is not recognizing the decorator I need to use. Any suggestions on how to resolve this? ...

Utilizing AngularFire2 FirebaseListObservable in various (routed) sections of an application

Currently, I am working on developing a social platform for our sailing club using Angular2/Firebase/AngularFire. The initial module aims to enable users to search for a club member based on various criteria (filters), which are approximately 10 in number. ...

Using rxjs for exponential backoff strategy

Exploring the Angular 7 documentation, I came across a practical example showcasing the usage of rxjs Observables to implement an exponential backoff strategy for an AJAX request: import { pipe, range, timer, zip } from 'rxjs'; import { ajax } f ...

iOS displaying CSS Transform issue exclusively

Creating a website that is fully mobile responsive is my goal. However, after designing the header, I realized that it wasn't displaying correctly on IOS devices like my iPad. The "Transform: translateX(-100%);" statement was functional on Android pho ...

Having trouble replicating the app freeze, any suggestions on how to troubleshoot it?

After releasing an update of our app (swift) on the App Store, some users reported that it was freezing and not functional after one day. We tested the same build from the App Store on our devices and everything worked fine. We even used the accounts of a ...

Expectation in Observable: Unable to provide data retrieval

In my Angular 7 and Typescript project, I am faced with the challenge of reading a json file from within a zip file. Although I am able to successfully display the correct json output on the console, I am struggling to return this json data from the functi ...

The URL launcher in Flutter does not properly handle iOS App Store links

In my Flutter app, I am using url_launcher to open an app directly in the iOS App Store on iOS devices. The URL is: Previously, I had enabled mode: LaunchMode.externalNonBrowserApplication to launch the app in the App Store directly, and it was working fi ...

Aframe failing to display image when using local path in Angular with AR.js

I am attempting to load an image from a local path within my Angular app component.html file. Below is the code snippet: <a-scene embedded arjs> <a-assets> <img id="test_img" src="/mnt/r/flipkart/proj/src/app ...

Upon the first page load, two menus appeared on the screen

Upon launching the app, both Main Menu and Menu One should be visible right away. I'm struggling to simplify my code in order to implement this feature efficiently. https://stackblitz.com/edit/angular-3q8e8q data = SideMenu.data.subOptions[0].child ...

Seeking the Origin of NgxMqttServiceConfig Import: Dealing with NullInjectorError in Angular Testing

While working on an application using Angular 8 and ngx-mqtt, I encountered an error when running the tests defined in the .spec.ts files. The error message reads: NullInjectorError: StaticInjectorError(DynamicTestModule)[InjectionToken NgxMqttServ ...

Customizing build settings for specific architectures in Xcode 7.2: A step-by-step guide

Does anyone know how to configure the build settings in Xcode for different architectures such as arm64 and armv7? I recently updated to Xcode 7.2 and it seems the option to do so is no longer available. In the past, I could expand a setting to access Deb ...

Fixing the error "cannot call a function which is possibly undefined" in React and TypeScript

Seeking a resolution to the error "cannot invoke an object which can possibly be undefined" by utilizing react and typescript. What is the issue at hand? The problem arises when using the useContext react hook to create a variable (dialogContext) in compo ...