sending notifications to Huawei does not work via gRPC
- Dominant language
- Go
- Stars
- 8.8k
- Forks
- 887
- PR merge metrics
- No merged PRs in 30d
Description
**My code:**
```go
func (g *GrpcGorush) SendToHuaweiAndroid(body Notification, index int, uuids []string) {
request, err := g.gorushClient.Send(context.Background(), &proto.NotificationRequest{
Platform: 3,
Tokens: uuids,
// Message: body.Annotations,
// Title: body.Title,
// Priority: proto.NotificationRequest_NORMAL,
// Image: body.ImageMedia,
Data: &structpb.Struct{
Fields: map[string]*structpb.Value{
"title": {
Kind: &structpb.Value_StringValue{StringValue: body.Title},
},
"href": {
Kind: &structpb.Value_StringValue{StringValue: body.NotifiHref},
},
"image": {
Kind: &structpb.Value_StringValue{StringValue: body.ImageMedia},
},
},
},
})
if err != nil {
g.logger.Info().Int("Chunk", index).Err(err)
}
if request != nil {
g.logger.Info().Int("Chunk", index).Msgf("Success: %t", request.Success)
g.logger.Info().Int("Chunk", index).Msgf("Count: %d", request.Counts)
}
}
```
**Server log:**
```
{"level":"debug","msg":"Start push notification for Huawei","time":"2024-04-26T10:58:22Z"}
{"level":"debug","msg":"Default message is {\"validate_only\":false,\"message\":{\"android\":{\"urgency\":\"NORMAL\",\"ttl\":\"86400s\"},\"token\":[\"IQAAAACy0sAbAACa6SbyCxYQWR2iMqGJMv....\"]}}","time":"2024-04-26T10:58:22Z"}
{"level":"debug","msg":"Huawei Send Notification is failed! Code: 80100003","time":"2024-04-26T10:58:22Z"}
```
If I send a message via web api then everything is sent correctly
```bash
curl -X POST -H 'Content-Type: application/json' https://push.dev/api/push -d @payload_huawei.json
```
**payload_huawei.json**
```json
{
"notifications": [
{
"tokens": ["IQAAAACy0sAbAACa6SbyCxYQWR2iMqGJMv..."],
"platform": 3,
"huawei_data": "{'title': 'title text', 'href': 'app_name://n/2823280/?from=push', 'image': 'https://host/home/n/2024/20240419/a.jpg'}"
}
]
}
```
**Server log:**
```
{"level":"debug","msg":"Start push notification for Huawei","time":"2024-04-26T11:04:20Z"}
{"level":"debug","msg":"Default message is {\"validate_only\":false,\"message\":{\"data\":\"{'title': 'title text', 'href': 'app_name://n/2823280/?from=push', 'image': 'https://host/home/n/2024/20240419/a.jpg'}\",\"android\":{\"urgency\":\"NORMAL\",\"ttl\":\"86400s\"},\"token\":[\"IQAAAACy0sAbAACa6SbyCxYQWR2iMqGJMv...\"]}}","time":"2024-04-26T11:04:20Z"}
{"level":"debug","msg":"Huwaei Send Notification is completed successfully!","time":"2024-04-26T11:04:20Z"}
```
The NotificationRequest structure does not have a hoawei_data field. I can pass *structpb.Struct as Data, and not string as in huawei_data.
How to correctly pass a string to Data or is this some kind of bug in the implementation of the rpc server?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with proto.NotificationRequest, its Data field, and the Send RPC implementation, then compare the payload produced by the gRPC path with the working web API request and Huawei server logs. Reproduce the Huawei code 80100003 response and trace how Data is serialized; done means the gRPC request produces the equivalent Huawei data payload and is accepted successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, grpc
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100