|
| 1 | +# 🔔 Node.js Push Notifications with FCM Function |
| 2 | + |
| 3 | +Send push notifications to your users using Firebase Cloud Messaging (FCM). |
| 4 | + |
| 5 | +## 🧰 Usage |
| 6 | + |
| 7 | +### `POST` |
| 8 | + |
| 9 | +Send a push notification to a user. |
| 10 | + |
| 11 | +**Parameters** |
| 12 | + |
| 13 | +| Name | Description | Location | Type | Sample Value | |
| 14 | +| ------------ | ------------------------------------ | -------- | ------------------ | -------------- | |
| 15 | +| Content-Type | The content type of the request body | Header | `application/json` | N/A | |
| 16 | +| deviceToken | FCM device identifier | Body | String | `642...7cd` | |
| 17 | +| message | Message to send | Body | String | `Hello World!` | |
| 18 | + |
| 19 | +**Response** |
| 20 | + |
| 21 | +Sample `200` Response: |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "ok": true, |
| 26 | + "messageId": "as4jg109cbe1" |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +Sample `400` Response: |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "ok": false, |
| 35 | + "error": "Device token and message are required." |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +Sample `500` Response: |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "ok": false, |
| 44 | + "error": "Failed to send the message." |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +## ⚙️ Configuration |
| 49 | + |
| 50 | +| Setting | Value | |
| 51 | +| ----------------- | ------------- | |
| 52 | +| Runtime | Node (18.0) | |
| 53 | +| Entrypoint | `src/main.js` | |
| 54 | +| Build Commands | `npm install` | |
| 55 | +| Permissions | `any` | |
| 56 | +| Timeout (Seconds) | 15 | |
| 57 | + |
| 58 | +## 🔒 Environment Variables |
| 59 | + |
| 60 | +### FCM_PROJECT_ID |
| 61 | + |
| 62 | +A unique identifier for your FCM project. |
| 63 | + |
| 64 | +| Question | Answer | |
| 65 | +| ------------- | -------------------------------------------------------------------------------------------------- | |
| 66 | +| Required | Yes | |
| 67 | +| Sample Value | `mywebapp-f6e57` | |
| 68 | +| Documentation | [FCM: Project ID](https://firebase.google.com/docs/projects/learn-more#project-id) | |
| 69 | + |
| 70 | +### FCM_CLIENT_EMAIL |
| 71 | + |
| 72 | +Your FCM service account email. |
| 73 | + |
| 74 | +| Question | Answer | |
| 75 | +| ------------- | -------------------------------------------------------------------------------------------------- | |
| 76 | +| Required | Yes | |
| 77 | +| Sample Value | `fcm-adminsdk-1a0de@test-f6e57.iam.gserviceaccount.com` | |
| 78 | +| Documentation | [FCM: SDK Setup](https://firebase.google.com/docs/admin/setup#initialize_the_sdk_in_non-google_environments) | |
| 79 | + |
| 80 | +### FCM_PRIVATE_KEY |
| 81 | + |
| 82 | +A unique private key used to authenticate with FCM. |
| 83 | + |
| 84 | +| Question | Answer | |
| 85 | +| ------------- | -------------------------------------------------------------------------------------------------- | |
| 86 | +| Required | Yes | |
| 87 | +| Sample Value | `0b6830cc66d92804e11af2153242d34211d675675` | |
| 88 | +| Documentation | [FCM: SDK Setup](https://firebase.google.com/docs/admin/setup#initialize_the_sdk_in_non-google_environments) | |
| 89 | + |
| 90 | +### FCM_DATABASE_URL |
| 91 | + |
| 92 | +URL of your FCM database. |
| 93 | + |
| 94 | +| Question | Answer | |
| 95 | +| ------------- | -------------------------------------------------------------------------------------------------- | |
| 96 | +| Required | Yes | |
| 97 | +| Sample Value | `https://my-app-e398e.firebaseio.com` | |
| 98 | +| Documentation | [FCM: SDK Setup](https://firebase.google.com/docs/admin/setup#initialize_the_sdk_in_non-google_environments) | |
0 commit comments