0
0
Firebasecloud~10 mins

Topic-based messaging in Firebase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to subscribe a device to a topic.

Firebase
firebase.messaging().subscribeToTopic(token, [1]);
Drag options to blanks, or click blank then click option'
AtopicName
Btoken
C'news'
D'user123'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the token instead of the topic name.
Not using quotes around the topic name.
2fill in blank
medium

Complete the code to send a message to a topic.

Firebase
admin.messaging().send({ topic: [1], notification: { title: 'Hello', body: 'World' } });
Drag options to blanks, or click blank then click option'
A'news'
Btoken
C'user123'
D'deviceToken'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a device token instead of a topic name.
Omitting quotes around the topic name.
3fill in blank
hard

Fix the error in the code to unsubscribe from a topic.

Firebase
firebase.messaging().[1](token, 'news');
Drag options to blanks, or click blank then click option'
AsubscribeToTopic
BunsubscribeFromTopic
CsendToTopic
DsendMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscribeToTopic instead of unsubscribeFromTopic.
Using sendToTopic which is for sending messages.
4fill in blank
hard

Fill both blanks to create a message payload for topic messaging with a data payload.

Firebase
const message = { topic: [1], data: { [2]: 'value' } };
Drag options to blanks, or click blank then click option'
A'sports'
B'score'
C'news'
D'title'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a data key that is not a string.
Mixing topic and data keys.
5fill in blank
hard

Fill all three blanks to send a notification message with a topic and a condition.

Firebase
const message = { [1]: 'weather', notification: { [2]: 'Alert', [3]: 'Rain expected' }, condition: "'weather' in topics || 'news' in topics" };
Drag options to blanks, or click blank then click option'
Atopic
Btitle
Cbody
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' instead of 'topic' for the topic key.
Mixing up title and body keys.