firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.14k stars 244 forks source link

FR - make Message Data interface{} instead map[string]string to allow other data types #170

Open sillysachin opened 6 years ago

sillysachin commented 6 years ago

Describe your environment

Describe the problem

Steps to reproduce:

We cannot use reuse a struct in the message data and instead we create a new map[string]string to be send as Data of FCM Message Data . So we have to trim out boolean, int , float into string and reprocess them again on swift and android code from string to correct datatypes.

This is terrible approach unwrapping structs at golang code and wrapping back string json into android/iOS pojos in client code.

Relevant Code:

// TODO(you): code here to reproduce the problem
article := Article{}
article.Title = "Awww"
article.Message = "This is so much work."
article.Source = "New Delhi"
article.Debug = true
article.Version = 1

articleData := map[string]string{
        "debug"      :   "true",
        "version"    :   "1",
        "source"     :   article.Source,
        "title"      :   article.Title,
        "message" :   article.Message,
}

message := &messaging.Message{
        Data:         articleData,
        Topic:        "debug",
        Notification: &messaging.Notification{Title: article.Title, Body: article.Message},
    }

We should be instead be able to use 

message := &messaging.Message{
        Data:         article,
        Topic:        "debug",
        Notification: &messaging.Notification{Title: article.Title, Body: article.Message},
    }
hiranya911 commented 6 years ago

Back-end API does not support arbitrary types in the Data field. It only supports string key-value pairs: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#Message

@sampson-chen to follow up.

sillysachin commented 6 years ago

Yes. Saw that when i modified the go code and tried to send out the data. But it runs counter to the firebase json concept of supporting notification with extra data. go-fcm is able to send the arbitrary data and works with android. Fails with iOS though. firebase-admin-go works with iOS but only supports string key-value making the coding on pojos terrible.

Cililing commented 2 years ago

I don't get it, the "legacy" way of sending messages allows to use map[string]any, but the "modern" framework does not. ¯_(ツ)_/¯

saamarthgupta01 commented 2 years ago

Has anyone been able to find a workaround for this?

9bany commented 3 months ago

+1