node.jsfirebasegoogle-cloud-messagingfirebase-cloud-messagingnode-red

node-red Firebase send notification


I'm trying to use fcm-push to send a notification to Android. I'm just not sure how to build the flow.

I've successfully made Firebase send a notification to android via the firebase console.

just need an example flow for fcm-push. thanks.


Solution

  • After much trial and error - I was able to come up with this. I did copy and then modify another example - unfortunately I don't know where the final example came from that I got to work (sorry). Here is one that is working, you can "import" into Node Red. Remember to change the AuthKey to your own.

        [
      {
        "id": "b765ca96.a1ef58",
        "type": "tab",
        "label": "Flow 1 _ send notifications to FCM",
        "disabled": false,
        "info": ""
      },
      {
        "id": "6ecb45a9.373ddc",
        "type": "inject",
        "z": "b765ca96.a1ef58",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 120,
        "y": 40,
        "wires": [
          [
            "aafc8341.84eae"
          ]
        ]
      },
      {
        "id": "3aab90c5.6c2a4",
        "type": "http request",
        "z": "b765ca96.a1ef58",
        "name": "http POST to Google FCM",
        "method": "POST",
        "ret": "txt",
        "url": "https:\/\/fcm.googleapis.com\/fcm\/send",
        "tls": "",
        "x": 180,
        "y": 220,
        "wires": [
          [
            "8d1dc739.0b7ac8"
          ]
        ]
      },
      {
        "id": "aafc8341.84eae",
        "type": "function",
        "z": "b765ca96.a1ef58",
        "name": "set payload and headers",
        "func": "msg.payload = {\"to\": \"\/topics\/news\",\"data\": {\"message\": \"This is a FCM Topic Message!\"},\"notification\":{\"body\" : \"some_message\"}};\nmsg.headers = {\"Authorization\": \"key=BDzaSyCN932874928374-d1Jz3Rkcvbcr4\"};\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 170,
        "y": 120,
        "wires": [
          [
            "3aab90c5.6c2a4"
          ]
        ]
      },
      {
        "id": "8d1dc739.0b7ac8",
        "type": "debug",
        "z": "b765ca96.a1ef58",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "complete": "false",
        "x": 290,
        "y": 340,
        "wires": [
    
        ]
      }
    ]