আপনি অ্যাডমিন SDK বা FCM v1 HTTP API ব্যবহার করে একটি নির্দিষ্ট বিষয়ে সদস্যতা নেওয়া ডিভাইসগুলিতে বার্তা পাঠাতে পারেন৷
পূর্বশর্ত
আপনার নির্বাচিত পদ্ধতি ব্যবহার করে বার্তা পাঠানোর জন্য প্রয়োজনীয় পরিবেশ সেট আপ করুন। আপনার সার্ভার এনভায়রনমেন্ট সেট আপ দেখুন।
ক্লায়েন্ট অ্যাপগুলিকে অবশ্যই বিষয়টিতে সদস্যতা নিতে হবে। বিষয় সদস্যতা পরিচালনা দেখুন।
একটি বিষয় পাঠানো হচ্ছে
আপনি Firebase Admin SDK বা FCM HTTP v1 API ব্যবহার করে কোনো বিষয়ে বার্তা পাঠাতে পারেন।
অ্যাডমিন SDK ব্যবহার করে
আপনি আপনার সার্ভার থেকে বিষয় বার্তা পাঠাতে অ্যাডমিন SDK ব্যবহার করতে পারেন। অ্যাডমিন SDK সেট আপ সম্পর্কে আরও জানতে, অ্যাডমিন SDK ব্যবহার করে বার্তা পাঠান দেখুন।
Node.js
// The topic name can be optionally prefixed with "/topics/".
const topic = 'highScores';
const message = {
data: {
score: '850',
time: '2:45'
},
topic: topic
};
// Send a message to devices subscribed to the provided topic.
getMessaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
জাভা
// The topic name can be optionally prefixed with "/topics/".
String topic = "highScores";
// See documentation on defining a message payload.
Message message = Message.builder()
.putData("score", "850")
.putData("time", "2:45")
.setTopic(topic)
.build();
// Send a message to the devices subscribed to the provided topic.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
পাইথন
# The topic name can be optionally prefixed with "/topics/".
topic = 'highScores'
# See documentation on defining a message payload.
message = messaging.Message(
data={
'score': '850',
'time': '2:45',
},
topic=topic,
)
# Send a message to the devices subscribed to the provided topic.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)
যাও
// The topic name can be optionally prefixed with "/topics/".
topic := "highScores"
// See documentation on defining a message payload.
message := &messaging.Message{
Data: map[string]string{
"score": "850",
"time": "2:45",
},
Topic: topic,
}
// Send a message to the devices subscribed to the provided topic.
response, err := client.Send(ctx, message)
if err != nil {
log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)
সি#
// The topic name can be optionally prefixed with "/topics/".
var topic = "highScores";
// See documentation on defining a message payload.
var message = new Message()
{
Data = new Dictionary<string, string>()
{
{ "score", "850" },
{ "time", "2:45" },
},
Topic = topic,
};
// Send a message to the devices subscribed to the provided topic.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);
HTTP v1 API ব্যবহার করে
HTTP v1 API ব্যবহার করে বিষয় বার্তা পাঠাতে, একটি JSON POST অনুরোধ তৈরি করুন। HTTP v1 API ব্যবহার সম্পর্কে আরও জানতে, FCM v1 API এর মাধ্যমে একটি বার্তা পাঠান দেখুন।
বিশ্রাম
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"topic" : "foo-bar",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message"
}
}
}
cURL কমান্ড:
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message": {
"topic" : "foo-bar",
"notification": {
"body": "This is a Firebase Cloud Messaging Topic Message!",
"title": "FCM Message"
}
}
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
বিষয় শর্তাবলী পাঠানো
বিষয়গুলির সংমিশ্রণে একটি বার্তা পাঠাতে, একটি শর্ত নির্দিষ্ট করুন, যা একটি বুলিয়ান অভিব্যক্তি যা লক্ষ্য বিষয়গুলি নির্দিষ্ট করে৷ উদাহরণস্বরূপ, নিম্নলিখিত শর্তটি TopicA
এবং TopicB
বা TopicC
তে সদস্যতা নেওয়া ডিভাইসগুলিতে বার্তা পাঠাবে:
"'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"
FCM প্রথমে বন্ধনীতে যেকোনো শর্ত মূল্যায়ন করে, এবং তারপর বাম থেকে ডানে অভিব্যক্তি মূল্যায়ন করে। আপনি আপনার শর্তাধীন অভিব্যক্তিতে পাঁচটি বিষয় পর্যন্ত অন্তর্ভুক্ত করতে পারেন।
অ্যাডমিন SDK ব্যবহার করে
Node.js
// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
const condition = '\'stock-GOOG\' in topics || \'industry-tech\' in topics';
// See documentation on defining a message payload.
const message = {
notification: {
title: '$FooCorp up 1.43% on the day',
body: '$FooCorp gained 11.80 points to close at 835.67, up 1.43% on the day.'
},
condition: condition
};
// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
getMessaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
জাভা
// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
String condition = "'stock-GOOG' in topics || 'industry-tech' in topics";
// See documentation on defining a message payload.
Message message = Message.builder()
.setNotification(Notification.builder()
.setTitle("$GOOG up 1.43% on the day")
.setBody("$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.")
.build())
.setCondition(condition)
.build();
// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
পাইথন
# Define a condition which will send to devices which are subscribed
# to either the Google stock or the tech industry topics.
condition = "'stock-GOOG' in topics || 'industry-tech' in topics"
# See documentation on defining a message payload.
message = messaging.Message(
notification=messaging.Notification(
title='$GOOG up 1.43% on the day',
body='$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
),
condition=condition,
)
# Send a message to devices subscribed to the combination of topics
# specified by the provided condition.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)
যাও
// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
condition := "'stock-GOOG' in topics || 'industry-tech' in topics"
// See documentation on defining a message payload.
message := &messaging.Message{
Data: map[string]string{
"score": "850",
"time": "2:45",
},
Condition: condition,
}
// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
response, err := client.Send(ctx, message)
if err != nil {
log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)
সি#
// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
var condition = "'stock-GOOG' in topics || 'industry-tech' in topics";
// See documentation on defining a message payload.
var message = new Message()
{
Notification = new Notification()
{
Title = "$GOOG up 1.43% on the day",
Body = "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.",
},
Condition = condition,
};
// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);
HTTP v1 API ব্যবহার করে
বিশ্রাম
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"condition": "'dogs' in topics || 'cats' in topics",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message",
}
}
}
cURL কমান্ড:
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"notification": {
"title": "FCM Message",
"body": "This is a Firebase Cloud Messaging Topic Message!",
},
"condition": "'dogs' in topics || 'cats' in topics"
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
অ্যাপে বিষয় বার্তা পরিচালনা করা
একবার আপনি একটি বিষয়ে একটি বার্তা পাঠালে, FCM এটি সমস্ত সাবস্ক্রাইব করা ক্লায়েন্ট অ্যাপ দৃষ্টান্তে বিতরণ করে।
আপনার অ্যান্ড্রয়েড, iOS বা ওয়েব অ্যাপে কীভাবে বার্তাগুলি গ্রহণ এবং প্রক্রিয়া করতে হয় তা জানতে, বার্তা গ্রহণ করুন দেখুন।