Web push messaging.setBackgroundMessageHandler not working - web-push

I implemented web-push notifications on my site with Google Firebase service.
firebase.google.com/docs/cloud-messaging/js/client
I tested it and everything works fine, but when my website window isn't in focus (it's in background) or closed and if I get push-notification it will disappear after 20 seconds.
In my https://hdlava.me/j/firebase_subscribe.js file I added
requireInteraction: true
flag in messaging.onMessage so if I get push mesage when my website is open the message won't disappear until I click on it.
I tried to add this
requireInteraction: true
in messaging.setBackgroundMessageHandler in my https://hdlava.me/firebase-messaging-sw.js, but it's not working. Even:
console.log('[firebase-messaging-sw.js] Received background message ', payload)
doesn't work. It looks like whole messaging.setBackgroundMessageHandler does not work.
Can someone please help me figure out what is the problem ? Also if I use in firebase-messaging-sw.js
self.addEventListener("push",function(event)
instead messaging.setBackgroundMessageHandler so I have two messges at once. First message disappears and second one doesn't, but second one is not clickable. Is it possible to prevent first message and make second one to be clickable ?

Referring to the FCM docs:
https://firebase.google.com/docs/cloud-messaging/js/receive
"Note: If you set notification fields in your HTTP or XMPP send request, those values take precedence over any values specified in the service worker."
So, if you have
{
"notification": {
"title": "Your title",
"body": "Your message"
},
"to": "topic",
}
It never triggers the BackgroundMessageHandler. Because sending data this way, simply overrides your variables. If you want to trigger it you need to send your notification like this:
{
"data": {
"notification": {
"title": "Your title",
"body": "Your message"
}
},
"to": "topic",
}

Related

How can I send documents with http request to power automate?

How can I send array documents and images with an HTTP request to power automate?
I am using type script with nodejs as backend.
Please see the code I am using below:
Services.ts:
sendEmailData( Notice_ID: string, Site_Notice_ID: string,EmailAddress:
string,Issued_To: string,Issue_To_Email: string,Description: string,Documents: any){
const postData: Post = {Notice_ID:Notice_ID, Site_Notice_ID:
Site_Notice_ID,EmailAddress: EmailAddress,Issued_To:Issued_To,
Issue_To_Email: Issue_To_Email,Description:Description, Documents: Documents};
this.http.post(this.SendEmailUrl, postData).subscribe(responseData => {
console.log(responseData)
});
}
Component.ts:
sendEmail(){
// console.log(emailData)
let Description = (document.getElementById("input2") as HTMLInputElement).value
this.postsService.sendEmailData(
emailData.Notice_ID,
emailData.Site_Notice_ID,
emailData.EmailAddress,
emailData.Issued_To,
emailData.Issue_To_Email,
Description,
this.Documents)
}
Power automate HTTP received sample:
{
"Notice_ID": "39208101",
"Site_Notice_ID": "392081",
"EmailAddress": "some#emailaddress.co.za",
"Issued_To": "Jay",
"Issue_To_Email": "some#emailaddress.co.za",
"Description": "",
"Documents": [
{},
{},
{}
]
}
You wanna send documents to PWA flow, right? What is the origin format and what format do you want to save these documents in? Where do you want to save them?
I'm considering you want to send them to PWA by a post request and save it in a OneDrive Business' folder.
{
"Notice_ID": "39208101",
"Site_Notice_ID": "392081",
"EmailAddress": "some#emailaddress.co.za",
"Issued_To": "Jay",
"Issue_To_Email": "some#emailaddress.co.za",
"Description": "",
"Documents": [ {"$content-type":"application/pdf","$content":"your base64 encoded
file here"}]
}
You can take a look at the complete example: https://api.npoint.io/073b1351d9b0cd0c7f88
Then, add the key "Documents" to a variable, like this:
Create an "apply to each" action to run your "documents" list.
For each dictionary in your document list, create a file:
In the "file content" field you can put the "Current action" variable.
Don't forget to create a counter or find some other way to name your created files with different names. You can also bring them named from your application and use the JSON body below:
"Documents": [ {"filename":"myfile.pdf","file":{"$content-
type":"application/pdf","$content":"your base64 encoded
file here"}}]
And set the filename in the "Apply to each":
Change the "file content":
You can use this website for generating base64 encoded files for testing your flow: https://base64.guru/converter/encode/pdf

Problem cancelling intent while filling intent parameter with word "disregard"

I have a google Action with intents that require slot/parameter filling. My Action was recently rejected by Google for leaving the mic open without prompting the user and I cannot resolve the issue.
As an example I have an intent named "trunk" which has a parameter "vehiclename".
I invoke the “trunk” intent without filling the vehiclename parameter. The assistant attempts to fill the first parameter by asking me “what is the vehicle name?” (verbiage I've defined to help with the slot filling). I respond with “disregard”. Then the assistant replies with “Sure, cancelling.” (or another similar phrase). I want to know where this response is coming from. The detailed response json is:
{
"conversationToken": "[]",
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Sure, cancelling.",
"displayText": "Sure, cancelling."
}
}
]
}
},
"possibleIntents": [
{
"intent": "assistant.intent.action.TEXT"
}
],
"speechBiasingHints": [
"$vehiclename"
]
}
],
"responseMetadata": {
"status": {
"message": "Success (200)"
},
"queryMatchInfo": {
"queryMatched": true,
"intent": "686ab942-5132-451b-9a16-16dbe8648ad0"
}
}
}
This response body has “expectUserResponse”: true which explains why the mic is being left open. And since the phrase "sure, cancelling" doesn't prompt the user, it violates google's design guidelines.
What’s important about this is that I have not created this response! It is nowhere in our intents, and it is not being returned by our API webhook. Our webhook is not even being called in any of this example.
Syntactically it makes sense that google assistant would treat “disregard” as any of the other stop words (e.g. “stop”, “cancel”, “never mind”, etc.) but it doesn’t treat it the same. Any of those other words exits the app as one would expect.
Furthermore, none of these stop words are invoking a “quit” intent which has the actions_intent_CANCEL event attached to it. According to google’s documentation here: https://developers.google.com/assistant/df-asdk/conversation-exits when uttering any of these exit words, the conversation should be routed through to our “quit” intent, but it doesn’t.
I’ve also tried attaching the actions_intent_NO_INPUT action to our quit intent, but that also isn’t triggered in this situation. After the assistant has responded with “sure, cancelling”, the conversation is basically stuck there and I can’t invoke another intent or provide any more dialog to prompt the user.
Main takeaway:
Where is this “sure, cancelling” response coming from?
How do we route the conversation to another intent from that response so that we can prompt the user again OR
How do we route the word “disregard” in such a way to avoid this errant response? Can we disable it?
reminder: this is only an issue when trying to fill an intent parameter, and it is only an issue with the word “disregard”

How to have an ms teams bot process the payload of a messageback card action

Looking for a node.js example of a bot processing the payload of a messageback card action.
The card appears valid and I see the displayText echoed back when I press the button.
And I get a valid 200 code back.
But, can't find an example of the bot processing the payload when the button is clicked.
{
"type": "Action.Submit",
"title": "Click me for messageBack",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "I clicked this button",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
}
For better understanding copying comments to answer:
When you click on card button it will send a message back which is mentioned in the displayed text, and you will receive on message activity event, there you can handle the code. You will receive the payload value under activity

Text from dashboard not showing sub-property from payload

I've been using dashboard's Text node to show msg.payload.time in web-ui without any issues. However, I recently updated my dashboard to version 2.3.10 and now my Text node is not showing anything.
This is my data model:
{
"topic": "agent/last-download",
"payload": {
"time": "2017-05-15 16:48:43",
"name": "dummy name",
"path": "/mnt/externalDrive/dummyFolder"
},
"qos": 0,
"retain": true,
"_topic": "agent/last-download",
"_msgid": "1c476895.e3b897"
}
This is how I'm setting Value format:
{{msg.payload.time}}
When I output msg.payload.time to debug node, it works fine. Or if I set msg.payload to Text then it also works but dumps complete payload as text - which is not my requirement. I've also tested setting msg.topic, msg._msgid and etc. to Text and they all work fine.
Any idea why the behavior is changed? or Is there any other way to retrieve payload's sub values?
This is a regression in behaviour in the 2.3.10.
Until a fix is released, you can add a Change node ahead of the ui_text node to move msg.payload.time to msg.payload and the value will be displayed.

Why can't send queue message text to an Azure Function?

I have an Azure Logic App with a queue trigger. The queue message is JSON. When I send "Message text" to an Azure function, I get
UnsupportedMediaType
{
"Message": "The WebHook request must contain an entity body formatted as JSON."
}
I'd assumed this would work directly.I tried setting request body to
#{json(<Message text>)}
where is the select dynamic content item, but I get red message "Enter a valid json".
What's the trick to making this connection? Do I have to pass in and then parse out "Message text" in my function? Again, I assumed it would do that automagically.
The #{} syntax indicates string interpolation. This means that your expression #{json(<Message text>)} de-serializes the message text to json, and then serializes it again.
Hence the expression that you want to use is
#json(<Message text>)
For future readers.
I was passing some (what seems to be to be valid) json to my webhook.
And kept getting the
"Message": "The WebHook request must contain an entity body formatted as JSON."
error.
:(
Finally, I found a json "expression" that did its voodoo and got rid of the error. I argument from the json-expression was my previous action's output, which was valid json. It apparently needs just a little help!
The raw (non designer) code was:
"GenericWebHookCsharpOne": {
"type": "Function",
"inputs": {
"body": "#json( body('MyPreviousAppLogicActionWhichIsAnAzureFunction'))",
"method": "POST",
"function": {
"id": "/xxxxxxxxxxxxxxxxxxxxxxxx
}

Resources