Home > database >  Firebase messaging error: Topic is malformed
Firebase messaging error: Topic is malformed

Time:08-12

I have been facing for some time the Malformed error on the firebase topic, inside a firebase Message.

When I try to create a firebase push notification, and I add the topic condition, it fails.

I can not find other questions solving my case.

I have been following this documentation

This is my topic string example: "'165' in topics || '16' in topics || '166' in topics || '15' in topics || '7' in topics"

I am not sure what could be wrong there.

This is my message construction code:

 new Message()
    {
        Data = new Dictionary<string, string>
        {
          
            ["Sound"] = SoundName, 
            ["UseSound"] = string.IsNullOrWhiteSpace(SoundName) ? "false" : "true",

        },
        Notification = new Notification
        {
            Title = $"{Interest.ToTitleCase()}Update",
            Body = Title
        },
        // Next line I think, its where the error is.
        Topic = string.Join(" || ", Tags.Select(t => $"'{t}' in topics")) 
    };

CodePudding user response:

After one day I suddenly paid more attention and discovered that, in order to get a condition worker, I should have use the Condition property instead of Topic .

new Message()
    {
        Data = new Dictionary<string, string>
    {
      
        ["Sound"] = SoundName, 
        ["UseSound"] = string.IsNullOrWhiteSpace(SoundName) ? "false" : "true",

    },
    Notification = new Notification
    {
        Title = $"{Interest.ToTitleCase()}Update",
        Body = Title
    },
    // Condition instead of Topic.
    Condition = string.Join(" || ", Tags.Select(t => $"'{t}' in topics")) 
};
  • Related