Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sending notifications to Huawei does not work via gRPC #765

Open
vanohaker opened this issue Apr 26, 2024 · 1 comment
Open

sending notifications to Huawei does not work via gRPC #765

vanohaker opened this issue Apr 26, 2024 · 1 comment

Comments

@vanohaker
Copy link

vanohaker commented Apr 26, 2024

My code:

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

curl -X POST -H 'Content-Type: application/json' https://push.dev/api/push -d @payload_huawei.json

payload_huawei.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?

@appleboy
Copy link
Owner

I will take it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants