-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.rb
57 lines (47 loc) · 1.34 KB
/
index.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'novu'
client = Novu::Client.new('MY_API_TOKEN')
puts client.notifications
# create a subscriber
create_payload = {
'subscriberId' => '7789', # replace with system_internal_user_id
'firstName' => 'John', # optional
'lastName' => 'Doe', # optional
}
client.create_subscriber(create_payload)
# Update subscriber detail
update_payload = {
'email' => '[email protected]', # replace with valid email
'firstName' => '<insert-firstname>', # optional
'lastName' => 'Obasanjo', # optional
}
client.update_subscriber('7789', update_payload);
# trigger a notification
trigger_payload = {
'name' => 'Trigger1',
'payload' => {
'first-name' => 'Adam'
},
'to' => {
'subscriberId' => '7789'
}
}
client.trigger_event(trigger_payload)
create_topic_payload = {
'key' => 'frontend-users',
'name' => 'All frontend users'
}
client.create_topic(create_topic_payload)
topicKey = 'frontend-users';
subscribers = ['6460925ce1a93324257d2fc1', '7789'].to_s
# Add subscribers to a topic
client.add_subscribers(topicKey, subscribers)
# Remove subscribers from a topic
client.remove_subscribers(topicKey, subscribers)
# Send notifications to a topic (all frontend users)
client.trigger_event({
'name' => 'Trigger1',
'to' => {
'type' => 'Topic',
'topicKey' => 'frontend-users'
}
})