Skip to content

Commit 1a131a1

Browse files
Merge pull request #21 from ravenappdev/feature/react-push-sdk
topics
2 parents 717f6b4 + b72aa3b commit 1a131a1

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

docs/push/client-sdk/react-js.mdx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private String hmacSha256Signature(String userId, String apiKey) {
190190
#### 5.1 Before user logs in
191191

192192
- You need to do this step if you want to send notifications to the user who has not logged in yet.
193-
You will have to use Firebase topics to send notifications which is described in detail in the More section.
193+
You will have to use Firebase topics to send notifications which is described in detail in the Sending Messages section.
194194

195195
- Now you can use the following method to initialize Raven before login.
196196

@@ -240,7 +240,53 @@ useEffect(() => {
240240
}, []);
241241
```
242242

243-
##
243+
## Sending messages
244+
245+
Follow the [Sending Push](/push/sending-push) doc to setup Firebase and create an event on the Raven console. Once done you can use Raven API to send push notifications.
246+
247+
### 1. Sending 1:1 to a user
248+
249+
To send a notification directly to a user you can pass either the registered fcm_tokens of the user or just pass the userId. Sending to userId will work if you are using Raven to manage the Firebase tokens.
250+
In this case, Raven SDK takes care of managing tokens and will send the notification to all the tokens registered for the userId.
251+
252+
```bash
253+
curl --location --request POST 'https://api.ravenapp.dev/v1/apps/{APP_ID}/events/send' \
254+
--header 'Authorization: AuthKey {API_KEY}' \
255+
--header 'Content-Type: application/json' \
256+
--data-raw '{
257+
"event" : {EVENT_NAME},
258+
"user": {
259+
"fcm_tokens": [{LIST_OF_TOKENS}]
260+
"user_id": {USER_ID}
261+
}
262+
}'
263+
```
264+
265+
### 2. Sending to a group of users
266+
267+
To send to a group of users, you can use Firebase Topics. In this case, you will have to register the user to a topic using Raven SDK. The SDK has two methods:
268+
269+
```javascript
270+
import { subscribeFirebaseTopic, unsubscribeFirebaseTopic } from "@ravenapp/raven-web-react-sdk";
271+
272+
subscribeFirebaseTopic(["TOPIC_NAME"]);
273+
unsubscribeFirebaseTopic(["TOPIC_NAME"]);
274+
```
275+
276+
You can pass the list of topics to subscribe a user. Note that this can be done only once you have initialized Firebase, retrieved the Firebase token and initialized Raven.
277+
Once subscribed you can pass the fcm_topic in the Raven API -
278+
279+
```bash
280+
curl --location --request POST 'https://api.ravenapp.dev/v1/apps/{APP_ID}/events/send' \
281+
--header 'Authorization: AuthKey {API_KEY}' \
282+
--header 'Content-Type: application/json' \
283+
--data-raw '{
284+
"event" : {EVENT_NAME},
285+
"user": {
286+
"fcm_topic": {TOPIC_NAME}
287+
}
288+
}'
289+
```
244290

245291
<Check>
246292
You are all set! Just fire Raven API and you should see your web push notification 👍 If you are

0 commit comments

Comments
 (0)