APNS Ex:
{
"content":
{
"aps":
{
"alert" : "",
"badge" : 37,
"sound" : "bingbong.aiff"
},
},
}
GCM Ex:
{
"content":
{
"registration_ids":
[
"abc...xyz",
"012...789",
"~!#...*_+"
],
"time_to_live":100,
"data":
{
"message":""
}
},
}
You can send a blank message. The question is what purpuse that blank message would serve.
In APNS, you can simply ommit the alert property from the payload, and no alert will be displayed (only the badge will be updated and the sound played).
In GCM, there is no special purpose to the message property. You can include whatever properties you wish inside the data dictionary, and it's up to you to decide what to do with those properties in your app.
Related
When the app is in foreground/background, everything is fine I can receive the notification, its data and the navigation works.
When the app is totally closed, I receive the notification but when I tap it I am being redirected to the main page, the data.wasTapped is not being triggered. It's like the app opens up with initial mode and I want it to go the data.confirm_page I send.
The noNotification is not working when the app is closed, any suggestions?
FCM:
FCM.onNotification(data => {
if (data.wasTapped) {
// should redirect to data.confirm_page
},
else {
// displaying a pop message, when the user confirms it sends him/her to the specified route
}
}
Push API:
{
"to": "fcm token",
"notification": {
"title": "this is the title",
"body": "this is the body",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "notification_icon",
"iconColor": "#e73439"
},
"android": {
"priority": "0"
},
"time_to_live_sec": 86400,
"data": {
"confirm_page": "/help",
"confirm_label": "OK",
"callback_data": {},
"reject_label": "Cancel"
}
}
I am testing a simple conversation from my dialogflow simulator using a fulfillment hosted in firebase functions.
And I am receiving the fulfillment response when triggered
But my simulator is showing this. Saying no response is received.
Please help
The complete RAW fulfillment response
{
"responseId": "99b660de-e2ca-4d8c-ace5-ef724fe5ee72",
"queryResult": {
"queryText": "male",
"parameters": {
"gender": "male"
},
"allRequiredParamsPresent": true,
"webhookPayload": {
"google": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Amazing"
}
}
]
},
"expectUserResponse": true,
"userStorage": "{\"data\":{}}"
}
},
"outputContexts": [
{
"name": "projects/assurance-purple/agent/sessions/bf891cbe-8642-eb61-ed7b-d6796adfab60/contexts/_actions_on_google",
"lifespanCount": 99,
"parameters": {
"data": "{}",
"gender.original": "male",
"gender": "male"
}
}
],
"intent": {
"name": "projects/assurance-purple/agent/intents/96b523a0-7a3a-4135-bdfc-d9d8ad16b661",
"displayName": "getGender"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 45
},
"languageCode": "en"
},
"webhookStatus": {
"message": "Webhook execution successful"
}
}
My actions on google Testing debug tab
`
{
"response": "We're sorry, but something went wrong. Please try again.",
"expectUserResponse": false,
"conversationToken": "",
"audioResponse": "",
"visualResponse": {
"visualElementsList": [
{
"displayText": {
"content": "Sorry, this action is not available in simulation"
}
}
],
"suggestionsList": [],
"agentLogoUrl": ""
},
"clientError": 4,
"is3pResponse": false
}
`
You don't show the entire response (copying and pasting it as text in your question would have been better), but it looks like you're sending a response back for an Action, but trying to test it in Dialogflow's conversation tool.
The Actions on Google response is slightly different than the response that Dialogflow expects to handle the additional features that the Assistant supports. Because of this, you need to use the Actions on Google simulator when testing your agent.
The Dialogflow test is looking for some specific fields to show the response that are not included with the actions-on-google library, and it will not show anything that is in a Google RichResponse object.
To summarize:
If you are working with an Action, use the Actions on Google simulator.
If you are working with other Dialogflow integrations, you can use the test tool on the right in Dialogflow.
Update
The error you're indicating from the AoG Simulator suggests that you're trying to just issue a statement in the conversation and not starting the Action, or that the Action has quit. Make sure you're talking to the action by starting it with "talk to my test app" or whatever the name of your Action is.
I'm trying to send a notification using firebase api and the notification is sent successfully if I only have "title" and "body" in the notification JSON object. However, if I add "sound":"default" to the notification object, as described in the documentation, I get the following error:
"Invalid JSON payload received. Unknown name \"sound\" at 'message.notification': Cannot find field."
My JSON object is as follows:
{"message":{"token": token, "notification":{"title":"Test", "body":"Test message from server", "sound":"default"}}}
The appearance of message in your JSON indicates you are using the HTTP v1 API. The documentation you linked is for the legacy API.
The HTTP v1 API JSON to send a notification with sound for Android and iOS devices should be:
{
"message": {
"token": "your-token-value",
"notification": {
"title": "Test",
"body": "Test message from server"
},
"android": {
"notification": {
"sound": "default"
}
},
"apns": {
"payload": {
"aps": {
"sound": "default"
}
}
}
}
}
I have a java based service as the provider and a node JS app as the consumer.
I used a stub runner here https://github.com/spring-cloud-samples/stub-runner-boot for Node JS to run against the wiremock. But whether it's Node JS, browser or curl as client I get this "cursor" text in place of generated string from regex elements.
This is the contract:
request {
method GET()
url value(consumer(regex('/v2/accounts/[0-9]+')))
}
response {
status 200
headers {
contentType(applicationJson())
}
body (
"firstName": regex('[a-zA-Z]*'),
"lastName": regex('[a-zA-Z]*'),
"kycStatus": regex('FAILED|PASSED|PENDING|ERROR'),
"address": [
"streetAddress" : "3244 jackson street",
"city" : "City",
"state" : regex('[a-zA-Z]{2}'),
"zipcode": regex('^\\d{5}\$')
]
)
}
This is the actual response from wiremock:
Response:
HTTP/1.1 200
Content-Type: [application/json]
{
"firstName": {
"cursor": 9
},
"lastName": {
"cursor": 9
},
"kycStatus": {
"cursor": 27
},
"address": {
"streetAddress": "3244 jackson street",
"city": "City",
"state": {
"cursor": 11
},
"zipcode": {
"cursor": 7
}
}
}
I noticed that your cursor values are actually the number of characters in your regex. So that told me something was definitely wrong. I've never ran into this before.
I think you need to wrap your regex with value()
request {
method GET()
url value(consumer(regex('/v2/accounts/[0-9]+')))
}
response {
status 200
headers {
contentType(applicationJson())
}
body (
"firstName": value(producer(regex('[a-zA-Z]*'))),
"lastName": value(producer(regex('[a-zA-Z]*'))),
"kycStatus": value(producer(regex('FAILED|PASSED|PENDING|ERROR'))),
"address": [
"streetAddress" : "3244 jackson street",
"city" : "City",
"state" : value(producer(regex('[a-zA-Z]{2}'))),
"zipcode": value(producer(regex('^\\d{5}\$')))
]
)
}
I came across another example that affects request payloads in the same way, when generating wiremock stubs.
If I do not add at least one "field" to the request body, for example:
request{
// ...
body (
value(consumer(regex("[a-zA-Z0-9]+")), producer("derp"))
)
}
the request payload is required to be
{
"cursor" : 12
}
as seen by this wiremock stub generated in target/META-INF/.../mappings/myContract.json
"bodyPatterns" : [ {
"equalToJson" : "{\"cursor\":12}",
"ignoreArrayOrder" : false,
"ignoreExtraElements" : false
} ]
Solution
All I needed to do was add at least one field to the request body
body (
aMadeUpField: value(consumer(regex("[a-zA-Z0-9]+")), producer("derp"))
)
And the regex will now work for that field, as seen by my regenerated wiremock stub
"bodyPatterns" : [ {
"matchesJsonPath" : "$[?(#.['aMadeUpField'] =~ /[a-zA-Z0-9]+/)]"
} ]
This is probably why there is a line hidden in the documentation saying only JSON is supported for the request body.
Edit: Another thing to check is "anyBoolean()" which should be changed to "aBoolean()" and "anInteger()" which should be "anyInteger()" (SCC is i guess really inconsistent with naming...). I double check if they are right in IntelliJ by ctrl + hovering over the groovy methods and making sure they return DslProperty or ClientDslProperty
And, as the other poster said, be sure to wrap any regex() with value() and play around with consumer() and producer() if needed.
I'm using FCM for a chat app. Everytime an user receives a message, I send him a notification via FCM. If user isn't with my web app in foreground, the message handling happens in a default Service Worker that generates a notification with the parameters I've specified on the body of my request. The problem is, everytime a new push message is sent and the app is in background, browsers (tested on Chrome and Firefox) are creating a new message instead of updating the existing one. I would like to keep the already visible notification and only update its value, is that possible?
Service Worker that handles the push if app isn't in foreground:
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': '*****'
});
const messaging = firebase.messaging();
JSON body of the request sent to FCM server
{
"priority" : "normal",
"collapse_key": "demo",
"notification": {
"title": "Felicius Humble",
"body": "This is a sample message content",
"click_action": "https://****.herokuapp.com",
"icon": "****"
},
"to": "****",
"data": {
"id": 7,
"timestamp": 1493573846692,
"content": "teste",
"type": "MESSAGE",
"direction": "OUTPUT",
"sender": {
"id": 5,
"name": "Felicius Humble",
"email": "****#gmail.com",
"gender": "MALE",
"picture": "****",
"facebookID": "****",
"fcmToken": "****",
"accessToken": "****"
},
"chatID": 3
}
}
Ok, so I've found this that shows all options available for the json body. For what I need I just need to add "tag" param on notification obj in my json body. If you want to update the notification, sent it with the same tag. Example:
{
"notification": {
"title": "",
"body": "",
"click_action": "",
"icon": "",
"tag" : "this must be the same for the notifications you want to update"
},
"to": "****",
"data": {}
}
}
There are scenarios where you might want a replacing notification to notify the user rather than silently update. Chat applications are a good example. In this case you should set tag and renotify to true.
write this code on your sw.js
const title = 'Notification 2 of 2';
const options = {
tag: 'renotify',
renotify: true
};
registration.showNotification(title, options);
You can test demo on here by clicking in renotify button