Skip to content

Commit 4a80d0f

Browse files
committed
refactor: topics page
1 parent 7fa599c commit 4a80d0f

File tree

1 file changed

+7
-102
lines changed

1 file changed

+7
-102
lines changed

concepts/topics.mdx

Lines changed: 7 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ Users can also assign a name to a topic. This name doesn't need to be unique and
1313

1414
A topic would get assigned different subscribers that will receive a notification every time a notification is sent to the topic.
1515

16+
## Common usecases
17+
18+
- Send to all users who have commented on a post.
19+
- Send to all users who subscribed to task updates.
20+
- Send an update to all tenant members
21+
- Other use cases that require sending a notification to a group of subscribers around a specific structure
22+
1623
## Create a topic
1724

1825
In order to be able to send a notification to a topic, first the user needs to create one. It can be done like this:
@@ -42,25 +49,6 @@ const key = "unique-topic-identifier";
4249
const result = await novu.topics.get(key);
4350
```
4451

45-
## Rename a topic
46-
47-
Descriptive name given during creation of topic can be changed later. This can be done like this:
48-
49-
```typescript
50-
import { Novu } from "@novu/node";
51-
52-
const novu = new Novu("<NOVU_SECRET_KEY>");
53-
54-
const topicKey = "posts:comment:12345";
55-
const topicName = "Post Comments";
56-
57-
const result = await novu.topics.rename(topicKey, topicName);
58-
```
59-
60-
This will return the whole Topic information, including the subscribers if having any.
61-
62-
<Note>Topic Key can not be changed</Note>
63-
6452
## Add subscribers to a topic
6553

6654
Adding subscribers to the topic is the main usecase of topic. A topic is like a group of subscribers. A notification can be sent to all subscribers of a topic at once
@@ -105,71 +93,8 @@ The field `succeeded` will return the array of subscriber ids that have been c
10593
To facilitate flows we allow to create a topic on the fly when adding subscribers.
10694

10795
If the topic key used does not exist for the selected environment and organization, Novu will create a new topic with name `Autogenerated-<TOPIC_KEY>` and the subscribers will be assigned to this newly created topic.
108-
10996
After that, that topic created on the fly can be managed in the same ways as the ones created in the normal way.
11097

111-
## Verify if subscriberId belongs to a topic
112-
113-
There would be times when it would be needed to verify if a certain subscriber belongs to a topic in order to decide what to do with that subscriber. The API call to achieve that is the following:
114-
115-
```typescript
116-
import { Novu } from "@novu/node";
117-
118-
const novu = new Novu("<NOVU_SECRET_KEY>");
119-
120-
const externalSubscriberId = "external-subscriber-id-1";
121-
const topicKey = "posts:comment:12345";
122-
123-
const response = await novu.topics.getSubscriber(
124-
topicKey,
125-
externalSubscriberId
126-
);
127-
```
128-
129-
<Note>
130-
The subscriberId to use in this API call is the one used as subscriber
131-
identifier. The choice was made to make easier for the user to use this
132-
without making extra calls to Novu.
133-
</Note>
134-
135-
## Remove a subscriber from a topic
136-
137-
A single or group of subscribers can be removed from an existing topic.
138-
139-
```typescript
140-
import { Novu } from '@novu/node';
141-
142-
const novu = new Novu("<NOVU_SECRET_KEY>");
143-
144-
const topicKey = 'posts:comment:12345';
145-
146-
const response = await novu.topics.removeSubscribers(topicKey, {
147-
subscribers: ['subscriber-id-1', 'subscriber-id-2', ...],
148-
});
149-
```
150-
151-
Where `subscribers` will be an array of the subscriberIds we want to remove from the topic. If successful an empty response will be returned.
152-
153-
## Delete a topic
154-
155-
An existing topic can be deleted using topic-key as topic-key is the unique identifier for a topic.
156-
157-
```typescript
158-
import { Novu } from "@novu/node";
159-
160-
const novu = new Novu("<NOVU_SECRET_KEY>");
161-
162-
const key = "unique-topic-identifier";
163-
164-
const result = await novu.topics.delete(key);
165-
```
166-
167-
<Warning>
168-
A topic can only be deleted if it doesn't have any subscriber added. When
169-
trying to delete a topic with subscribers a conflict error will be returned.
170-
This is done to prevent accidental topic deletions.
171-
</Warning>
172-
17398
## Trigger workflow to a topic
17499

175100
A workflow can be triggered to a single subscriber and an array of subscribers. While doing so, one need to send subscriberIds in `to` field. In case of trigger, we have already stored subscriberIds in a topic, so a topic key can be used to trigger a workflow. Workflow will be triggered to all subscribers in the topic.
@@ -183,22 +108,6 @@ await novu.trigger("<WORKFLOW_TRIGGER_IDENTIFIER>", {
183108
});
184109
```
185110

186-
## Trigger workflow to multiple topics
187-
188-
Workflow can be triggered to multiple subscribers by using an array of topics.
189-
190-
```typescript
191-
const topicKey = "<TOPIC-KEY-DEFINED-BY-THE-USER>";
192-
193-
await novu.trigger("<WORKFLOW_TRIGGER_IDENTIFIER>", {
194-
to: [
195-
{ type: "Topic", topicKey: topicKey },
196-
{ type: "Topic", topicKey: "Another Topic Key" },
197-
],
198-
payload: {},
199-
});
200-
```
201-
202111
## Exclude actor from topic trigger event
203112

204113
To exclude the actor responsible for the action of a triggered topic event, you must add the subscriberId of that actor when triggering that event.
@@ -213,10 +122,6 @@ await novu.trigger("<WORKFLOW_TRIGGER_IDENTIFIER>", {
213122
});
214123
```
215124

216-
## Usecase Example
217-
218-
User X makes a comment, other users (A, B) who've already commented before should get a notification. So, when triggering the notification on that topic, you would usually want to exclude User X from receiving a notification about their own comment. To do that - you would need to add User X's subscriberId to the trigger event.
219-
220125
## API
221126

222127
<CardGroup cols={3}>

0 commit comments

Comments
 (0)