Closed theanhoo closed 4 years ago
Hi @theanhoo ,
Apparantly FCMv1 does not tolerate values that are not a string within data
payload. I'm adding bugfix task to esl/sparrow
backlog.
Until this is resolved please pass all values as strings to MongoosePush API - here the problem is specifically with: "message-count": 1
.
Hi, @rslota,
I've removed binary_to_integer
from the following function in MongooseIM:
%% Create notification for API v2
make_notification(v2, Notification, Options = #{<<"silent">> := <<"true">>}) ->
%% MessageCount = binary_to_integer(maps:get(<<"message-count">>, Notification)),
MessageCount = maps:get(<<"message-count">>, Notification),
{ok, #{
service => maps:get(<<"service">>, Options),
mode => maps:get(<<"mode">>, Options, <<"prod">>),
topic => maps:get(<<"topic">>, Options, null),
priority => "high",
data => Notification#{<<"message-count">> => MessageCount}
}};
make_notification(v2, Notification, Options) ->
{ok, #{
service => maps:get(<<"service">>, Options),
mode => maps:get(<<"mode">>, Options, <<"prod">>),
alert => #{
body => maps:get(<<"last-message-body">>, Notification),
title => maps:get(<<"last-message-sender">>, Notification),
tag => maps:get(<<"last-message-sender">>, Notification),
badge => binary_to_integer(maps:get(<<"message-count">>, Notification)),
click_action => maps:get(<<"click_action">>, Options, null)
},
topic => maps:get(<<"topic">>, Options, null)
}}.
This is the request:
{
"message": {
"android": {
"data": {
"last-message-body": "6",
"last-message-sender": "user@example.com",
"message-count": "1"
},
"notification": {},
"priority": "HIGH"
},
"data": {},
"notification": {},
"token": "XXX"
}
}
And this is the response:
2019-11-28T16:55:39.082 [debug] pid=<0.1820.0> action=send, item=request_response, to={#PID<0.1971.0>, #Reference<0.733623136.701235201.235185>}, headers=[{":status", "400"}, {"vary", "X-Origin"}, {"vary", "Referer"}, {"vary", "Origin,Accept-Encoding"}, {"content-type", "application/json; charset=UTF-8"}, {"date", "Thu, 28 Nov 2019 08:55:39 GMT"}, {"server", "ESF"}, {"cache-control", "private"}, {"x-xss-protection", "0"}, {"x-frame-options", "SAMEORIGIN"}, {"x-content-type-options", "nosniff"}, {"alt-svc", "quic=\":443\"; ma=2592000; v=\"46,43\",h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000"}, {"accept-ranges", "none"}], body={
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
Please advise.
Many thanks in advance.
I have switched back to MongoosePush 1.0.6. That seems to work fine.
MongoosePush version: mongoose_push-2.0.0-alpha.4
on 24 November 2019
Request:
Response from FCM (error):
Please help.
Many thanks in advance.