Firebase Admin SDK ব্যবহার করে মেসেজ পাঠানো

আপনি Firebase Admin SDK এখনও সেট-আপ না করে থাকলে, আপনার সার্ভারে Firebase Admin SDK সেট-আপ করতে গাইড ফলো করুন।

FCM HTTP v1 API চালু করুন

  1. Firebase কনসোলে গিয়ে সেটিংস > সাধারণ বিকল্পে যান। তারপর, ক্লাউড মেসেজিং ট্যাবে ক্লিক করুন।

  2. Cloud Messaging API চালু করুন।

অন্য প্রোজেক্ট থেকে পরিষেবা অ্যাকাউন্টকে অনুমোদন করা

আপনি "প্রাপক প্রোজেক্ট" নামক একটি প্রোজেক্টে পরিষেবা অ্যাকাউন্ট ব্যবহার করার সময় "প্রাপক প্রোজেক্ট" নামক অন্য একটি প্রোজেক্টের জন্য মেসেজ পাঠাতে পারবেন। এর ফলে, আপনি অন্যদের হয়ে মেসেজ পাঠানোর সময় একটি প্রোজেক্টে পরিষেবা অ্যাকাউন্ট ম্যানেজমেন্ট সেন্ট্রালাইজ করতে পারবেন। এটি কীভাবে করবেন তা জানতে, নিম্নলিখিত ধাপগুলি অনুসরণ করুন:

  1. প্রেরকের প্রোজেক্টে, Firebase Cloud Messaging API চালু করা আছে কিনা ভালভাবে দেখে নিন। Firebase কনসোলে এটি চালু আছে কিনা তা চেক করতে সেটিংস > সাধারণ বিকল্পে যান। তারপর, ক্লাউড মেসেজিং ট্যাবে ক্লিক করুন।

  2. প্রেরক প্রোজেক্টে, একটি পরিষেবা অ্যাকাউন্ট তৈরি করুন।

  3. টার্গেট প্রোজেক্টে, পরিষেবা অ্যাকাউন্টের ইমেল আইডিতে Firebase Cloud Messaging API অ্যাডমিন ভূমিকা অ্যাসাইন করুন। আপনি এটি Google Cloud কনসোলের IAM ও অ্যাডমিন > IAM পৃষ্ঠা থেকে করতে পারেন। এই ভূমিকাটি প্রেরক প্রোজেক্টের পরিষেবা অ্যাকাউন্টকে টার্গেট প্রোজেক্টে মেসেজ পাঠানোর অনুমতি দেয়।

  4. প্রেরক প্রোজেক্টের পরিষেবা অ্যাকাউন্টের কী ফাইল এবং টার্গেট প্রোজেক্টের প্রোজেক্ট আইডি দিয়ে আপনার SDK ইনিশিয়ালাইজ করুন।

    Node.js

    import { initializeApp, applicationDefault } from 'firebase-admin/app';
    
    initializeApp({
      // The credential is configured to be the sender project's service
      // account key via the environment variable GOOGLE_APPLICATION_CREDENTIALS
      credential: applicationDefault(),
      projectId: '<TARGET_PROJECT_ID>',
    });
    

    জাভা

    FirebaseOptions options = FirebaseOptions.builder()
        // The credential is configured to be the sender project's service
        // account key via the environment variable GOOGLE_APPLICATION_CREDENTIALS
        .setCredentials(GoogleCredentials.getApplicationDefault())
        .setProjectId("<TARGET_PROJECT_ID>")
        .build();
    
    FirebaseApp.initializeApp(options);
    

    Python

    import firebase_admin
    
    app_options = {'projectId': '<TARGET_PROJECT_ID>'}
    # Initialize with the default credential, i.e. the sender project's service
    # account key, stored in GOOGLE_APPLICATION_CREDENTIALS
    default_app = firebase_admin.initialize_app(options=app_options)
    

    Go

    config := &firebase.Config{ProjectID: "<TARGET_PROJECT_ID>"}
    // Initialize with the default credential, i.e. the sender project's service
    // account key, stored in GOOGLE_APPLICATION_CREDENTIALS
    app, err := firebase.NewApp(context.Background(), config)
    if err != nil {
            log.Fatalf("error initializing app: %v\n", err)
    }
    

    C#

    FirebaseApp.Create(new AppOptions()
    {
        // The credential is configured to be the sender project's service
        // account key via the environment variable GOOGLE_APPLICATION_CREDENTIALS
        Credential = GoogleCredential.GetApplicationDefault(),
        ProjectId = "<TARGET_PROJECT_ID>",
    });
    

নির্দিষ্ট ডিভাইসে মেসেজ পাঠানো

কোনও নির্দিষ্ট ডিভাইসে পাঠানোর জন্য, আপনি সেটির Firebase ইনস্টলেশন আইডি (FID) অথবা রেজিস্ট্রেশন টোকেন টার্গেট করতে পারেন।

Node.js

FID ব্যবহার করা (সাজেস্ট করা হয়েছে):

// This installation ID comes from the client FCM SDKs.
const fid = 'YOUR_REGISTERED_FID';

const message = {
  data: {
    score: '850',
    time: '2:45'
  },
  fid: fid
};

// Send a message to the device corresponding to the provided FID.
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);
  });

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// This registration token comes from the client FCM SDKs.
const registrationToken = 'YOUR_REGISTRATION_TOKEN';

const message = {
  data: {
    score: '850',
    time: '2:45'
  },
  token: registrationToken
};

// Send a message to the device corresponding to the provided
// registration token.
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);
  });

জাভা

FID ব্যবহার করা (সাজেস্ট করা হয়েছে):

// This installation ID comes from the client FCM SDKs.
String fid = "YOUR_REGISTERED_FID";

// See documentation on defining a message payload.
Message message = Message.builder()
    .putData("score", "850")
    .putData("time", "2:45")
    .setFid(fid)
    .build();

// Send a message to the device corresponding to the provided FID.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// This registration token comes from the client FCM SDKs.
String registrationToken = "YOUR_REGISTRATION_TOKEN";

// See documentation on defining a message payload.
Message message = Message.builder()
    .putData("score", "850")
    .putData("time", "2:45")
    .setToken(registrationToken)
    .build();

// Send a message to the device corresponding to the provided
// registration token.
String response = FirebaseMessaging.getInstance().sendAsync(message).get();
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);

Python

FID ব্যবহার করা (সাজেস্ট করা হয়েছে):

# This installation ID comes from the client FCM SDKs.
fid = 'YOUR_REGISTERED_FID'

# See documentation on defining a message payload.
message = messaging.Message(
    data={
        'score': '850',
        'time': '2:45',
    },
    fid=fid,
)

# Send a message to the device corresponding to the provided FID.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

# This registration token comes from the client FCM SDKs.
registration_token = 'YOUR_REGISTRATION_TOKEN'

# See documentation on defining a message payload.
message = messaging.Message(
    data={
        'score': '850',
        'time': '2:45',
    },
    token=registration_token,
)

# Send a message to the device corresponding to the provided
# registration token.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)

Go

FID ব্যবহার করা (সাজেস্ট করা হয়েছে):

// Obtain a messaging.Client from the App.
ctx := context.Background()
client, err := app.Messaging(ctx)
if err != nil {
    log.Fatalf("error getting Messaging client: %v\n", err)
}

// This installation ID comes from the client FCM SDKs.
fid := "YOUR_REGISTERED_FID"

// See documentation on defining a message payload.
message := &messaging.Message{
    Data: map[string]string{
        "score": "850",
        "time":  "2:45",
    },
    Fid: fid,
}

// Send a message to the device corresponding to the provided FID.
response, err := client.Send(ctx, message)
if err != nil {
    log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// Obtain a messaging.Client from the App.
ctx := context.Background()
client, err := app.Messaging(ctx)
if err != nil {
	log.Fatalf("error getting Messaging client: %v\n", err)
}

// This registration token comes from the client FCM SDKs.
registrationToken := "YOUR_REGISTRATION_TOKEN"

// See documentation on defining a message payload.
message := &messaging.Message{
	Data: map[string]string{
		"score": "850",
		"time":  "2:45",
	},
	Token: registrationToken,
}

// Send a message to the device corresponding to the provided
// registration token.
response, err := client.Send(ctx, message)
if err != nil {
	log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)

C#

FID ব্যবহার করা (সাজেস্ট করা হয়েছে):

// This installation ID comes from the client FCM SDKs.
var fid = "YOUR_REGISTERED_FID";

var message = new Message()
{
    Data = new Dictionary<string, string>()
    {
        { "score", "850" },
        { "time", "2:45" },
    },
    Fid = fid,
};

// Send a message to the device corresponding to the provided FID.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

            // This registration token comes from the client FCM SDKs.
            var registrationToken = "YOUR_REGISTRATION_TOKEN";

            // See documentation on defining a message payload.
            var message = new Message()
            {
                Data = new Dictionary<string, string>()
                {
                    { "score", "850" },
                    { "time", "2:45" },
                },
#pragma warning disable CS0618
                Token = registrationToken,
#pragma warning restore CS0618
            };

            // Send a message to the device corresponding to the provided
            // registration token.
            string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
            // Response is a message ID string.
            Console.WriteLine("Successfully sent message: " + response);

সফল হলে, প্রতিটি পাঠানোর পদ্ধতি একটি মেসেজ আইডি রিটার্ন করে। Firebase Admin SDK আইডি স্ট্রিংটি projects/{project_id}/messages/{message_id} ফর্ম্যাটে ফেরায়।

একাধিক ডিভাইসে একটি মেসেজ পাঠানো

অ্যাডমিন FCM SDK আপনাকে Firebase ইনস্টলেশন আইডি (FID) বা ডিভাইস রেজিস্ট্রেশন টোকেনের তালিকায় মাল্টিকাস্ট মেসেজ পাঠাতে দেয়। অনেক ডিভাইসে একই মেসেজ পাঠানোর প্রয়োজন হলে আপনি এই ফিচার ব্যবহার করতে পারবেন। আপনি প্রতিটি ইনভোকেশন পিছু সর্বাধিক ৫০০টি FID এবং/অথবা টোকেন নির্দিষ্ট করতে পারবেন।

রিটার্ন ভ্যালুতে উত্তরের একটি তালিকা থাকে যা ইনপুট টার্গেট, FID এবং/অথবা টোকেনের ক্রমের সাথে সঙ্গতিপূর্ণ। কোন টার্গেটের জন্য সমস্যা হয়েছে তা চেক করতে এটি কাজে লাগে। টোকেন ও FID, দুটিই প্রদান করা হলে, প্রথমে টোকেন প্রসেস করা হয়, তারপরে FID প্রসেস করা হয়।

Node.js

FID ব্যবহার করা (সাজেস্ট করা):

// These Firebase Installation IDs (FIDs) come from the client FCM SDKs.
const fids = [
  'YOUR_REGISTERED_FID_1',
  // ...
  'YOUR_REGISTERED_FID_N'
];

const message = {
  data: {score: '850', time: '2:45'},
  fids: fids,
};

getMessaging().sendEachForMulticast(message)
  .then((response) => {
    console.log(response.successCount + ' messages were sent successfully');
    if (response.failureCount > 0) {
      const failedFids = [];
      response.responses.forEach((resp, idx) => {
        if (!resp.success) {
          failedFids.push(fids[idx]);
        }
      });
      console.log('List of FIDs that caused failures: ' + failedFids);
    }
  });

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// These registration tokens come from the client FCM SDKs.
const registrationTokens = [
  'YOUR_REGISTRATION_TOKEN_1',
  // …
  'YOUR_REGISTRATION_TOKEN_N',
];

const message = {
  data: {score: '850', time: '2:45'},
  tokens: registrationTokens,
};

getMessaging().sendEachForMulticast(message)
  .then((response) => {
    if (response.failureCount > 0) {
      const failedTokens = [];
      response.responses.forEach((resp, idx) => {
        if (!resp.success) {
          failedTokens.push(registrationTokens[idx]);
        }
      });
      console.log('List of tokens that caused failures: ' + failedTokens);
    }
  });

জাভা

FID ব্যবহার করা (সাজেস্ট করা হয়েছে):

// These Firebase Installation IDs (FIDs) come from the client FCM SDKs.
List<String> fids = Arrays.asList(
    "YOUR_REGISTERED_FID_1",
    // ...
    "YOUR_REGISTERED_FID_N"
);

MulticastMessage message = MulticastMessage.builder()
    .putData("score", "850")
    .putData("time", "2:45")
    .addAllFids(fids)
    .build();

BatchResponse response = FirebaseMessaging.getInstance().sendEachForMulticast(message);
if (response.getFailureCount() > 0) {
  List<SendResponse> responses = response.getResponses();
  List<String> failedFids = new ArrayList<>();
  for (int i = 0; i < responses.size(); i++) {
    if (!responses.get(i).isSuccessful()) {
      // The order of responses corresponds to the order of the destination FIDs.
      failedFids.add(fids.get(i));
    }
  }
  System.out.println("List of FIDs that caused failures: " + failedFids);
}

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// These registration tokens come from the client FCM SDKs.
List<String> registrationTokens = Arrays.asList(
    "YOUR_REGISTRATION_TOKEN_1",
    // ...
    "YOUR_REGISTRATION_TOKEN_n"
);

MulticastMessage message = MulticastMessage.builder()
    .putData("score", "850")
    .putData("time", "2:45")
    .addAllTokens(registrationTokens)
    .build();
BatchResponse response = FirebaseMessaging.getInstance().sendEachForMulticast(message);
if (response.getFailureCount() > 0) {
  List<SendResponse> responses = response.getResponses();
  List<String> failedTokens = new ArrayList<>();
  for (int i = 0; i < responses.size(); i++) {
    if (!responses.get(i).isSuccessful()) {
      // The order of responses corresponds to the order of the registration tokens.
      failedTokens.add(registrationTokens.get(i));
    }
  }

  System.out.println("List of tokens that caused failures: " + failedTokens);
}

Python

FID ব্যবহার করা (সাজেস্ট করা):

# These Firebase Installation IDs (FIDs) come from the client FCM SDKs.
fids = [
    'YOUR_REGISTERED_FID_1',
    # ...
    'YOUR_REGISTERED_FID_N',
]

message = messaging.MulticastMessage(
    data={'score': '850', 'time': '2:45'},
    fids=fids,
)
response = messaging.send_each_for_multicast(message)
if response.failure_count > 0:
    responses = response.responses
    failed_fids = []
    for idx, resp in enumerate(responses):
        if not resp.success:
            # The order of responses corresponds to the order of the destination FIDs.
            failed_fids.append(fids[idx])
    print('List of FIDs that caused failures: {0}'.format(failed_fids))

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

# These registration tokens come from the client FCM SDKs.
registration_tokens = [
    'YOUR_REGISTRATION_TOKEN_1',
    # ...
    'YOUR_REGISTRATION_TOKEN_N',
]

message = messaging.MulticastMessage(
    data={'score': '850', 'time': '2:45'},
    tokens=registration_tokens,
)
response = messaging.send_each_for_multicast(message)
if response.failure_count > 0:
    responses = response.responses
    failed_tokens = []
    for idx, resp in enumerate(responses):
        if not resp.success:
            # The order of responses corresponds to the order of the registration tokens.
            failed_tokens.append(registration_tokens[idx])
    print(f'List of tokens that caused failures: {failed_tokens}')

Go

FID ব্যবহার করা (সাজেস্ট করা হয়েছে):

// Create a list containing up to 500 Firebase Installation IDs (FIDs).
// These Firebase Installation IDs (FIDs) come from the client FCM SDKs.
fids := []string{
    "YOUR_REGISTERED_FID_1",
    // ...
    "YOUR_REGISTERED_FID_N",
}

message := &messaging.MulticastMessage{
    Data: map[string]string{
        "score": "850",
        "time":  "2:45",
    },
    Fids: fids,
}

br, err := client.SendEachForMulticast(ctx, message)
if err != nil {
    log.Fatalln(err)
}

if br.FailureCount > 0 {
    var failedFids []string
    for idx, resp := range br.Responses {
        if !resp.Success {
            // The order of responses corresponds to the order of the destination FIDs.
            failedFids = append(failedFids, fids[idx])
        }
    }
    fmt.Printf("List of FIDs that caused failures: %v\n", failedFids)
}

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// Create a list containing up to 500 registration tokens.
// This registration tokens come from the client FCM SDKs.
registrationTokens := []string{
	"YOUR_REGISTRATION_TOKEN_1",
	// ...
	"YOUR_REGISTRATION_TOKEN_n",
}
message := &messaging.MulticastMessage{
	Data: map[string]string{
		"score": "850",
		"time":  "2:45",
	},
	Tokens: registrationTokens,
}

br, err := client.SendEachForMulticast(context.Background(), message)
if err != nil {
	log.Fatalln(err)
}

if br.FailureCount > 0 {
	var failedTokens []string
	for idx, resp := range br.Responses {
		if !resp.Success {
			// The order of responses corresponds to the order of the registration tokens.
			failedTokens = append(failedTokens, registrationTokens[idx])
		}
	}

	fmt.Printf("List of tokens that caused failures: %v\n", failedTokens)
}

C#

FID ব্যবহার করা (সাজেস্ট করা):

// These Firebase Installation IDs (FIDs) come from the client FCM SDKs.
var fids = new List<string>()
{
    "YOUR_REGISTERED_FID_1",
    // ...
    "YOUR_REGISTERED_FID_N",
};

var message = new MulticastMessage()
{
    Data = new Dictionary<string, string>()
    {
        { "score", "850" },
        { "time", "2:45" },
    },
    Fids = fids,
};

var response = await FirebaseMessaging.DefaultInstance.SendEachForMulticastAsync(message);

if (response.FailureCount > 0)
{
    var failedFids = new List<string>();
    for (var i = 0; i < response.Responses.Count; i++)
    {
        if (!response.Responses[i].IsSuccess)
        {
            // The order of responses corresponds to the order of the destination FIDs.
            failedFids.add(fids[i]);
        }
    }
    Console.WriteLine($"List of FIDs that caused failures: {string.Join(", ", failedFids)}");
}

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

            // These registration tokens come from the client FCM SDKs.
            var registrationTokens = new List<string>()
            {
                "YOUR_REGISTRATION_TOKEN_1",
                // ...
                "YOUR_REGISTRATION_TOKEN_n",
            };
            var message = new MulticastMessage()
            {
#pragma warning disable CS0618
                Tokens = registrationTokens,
#pragma warning restore CS0618
                Data = new Dictionary<string, string>()
                {
                    { "score", "850" },
                    { "time", "2:45" },
                },
            };

            var response = await FirebaseMessaging.DefaultInstance.SendEachForMulticastAsync(message);
            if (response.FailureCount > 0)
            {
                var failedTokens = new List<string>();
                for (var i = 0; i < response.Responses.Count; i++)
                {
                    if (!response.Responses[i].IsSuccess)
                    {
                        // The order of responses corresponds to the order of the registration tokens.
                        failedTokens.Add(registrationTokens[i]);
                    }
                }

                Console.WriteLine($"List of tokens that caused failures: {failedTokens}");
            }

মেসেজের তালিকা পাঠানো

Admin SDK-এর মাধ্যমে সর্বাধিক ৫০০টি মেসেজের তালিকা পাঠানো যায়। এই ফিচারটি মেসেজের কাস্টমাইজ করা সেট তৈরি করতে এবং সেগুলি বিভিন্ন প্রাপকদের পাঠাতে ব্যবহার করা যেতে পারে, এর মধ্যে বিষয়, Firebase ইনস্টলেশন আইডি (FID) বা ডিভাইস রেজিস্ট্রেশন টোকেন অন্তর্ভুক্ত। যেমন, আপনি এই ফিচারটি তখন ব্যবহার করতে পারেন যখন আপনাকে বিভিন্ন দর্শকদের কাছে আলাদা আলাদা মেসেজ পাঠাতে হয়।

Node.js

মিশ্র টার্গেট ব্যবহার করা (সাজেস্ট করা):

// Create a list containing up to 500 messages.
const messages = [
  {
    notification: { title: 'Price drop', body: '5% off all electronics' },
    fid: 'YOUR_REGISTERED_FID', // Using FID (Recommended)
  },
  {
    notification: { title: 'Price drop', body: '2% off all books' },
    token: 'YOUR_REGISTRATION_TOKEN', // Using token (Deprecated)
  },
  {
    notification: { title: 'Price drop', body: '10% off all shoes' },
    topic: 'readers-club',
  }
];

getMessaging().sendEach(messages)
  .then((response) => {
    console.log(response.successCount + ' messages were sent successfully');
  });

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// Create a list containing up to 500 messages.
const messages = [];
messages.push({
  notification: { title: 'Price drop', body: '5% off all electronics' },
  token: registrationToken,
});
messages.push({
  notification: { title: 'Price drop', body: '2% off all books' },
  topic: 'readers-club',
});

getMessaging().sendEach(messages)
  .then((response) => {
    console.log(response.successCount + ' messages were sent successfully');
  });

জাভা

মিশ্র টার্গেট ব্যবহার করা (সাজেস্ট করা):

// Create a list containing up to 500 messages.
List<Message> messages = new ArrayList<>();
messages.add(Message.builder()
    .setNotification(Notification.builder()
        .setTitle("Price drop")
        .setBody("5% off all electronics")
        .build())
    .setFid("YOUR_REGISTERED_FID") // Using FID (Recommended)
    .build());
messages.add(Message.builder()
    .setNotification(Notification.builder()
        .setTitle("Price drop")
        .setBody("2% off all books")
        .build())
    .setToken("YOUR_REGISTRATION_TOKEN") // Using token (Deprecated)
    .build());
messages.add(Message.builder()
    .setNotification(Notification.builder()
        .setTitle("Price drop")
        .setBody("10% off all shoes")
        .build())
    .setTopic("readers-club")
    .build());

BatchResponse response = FirebaseMessaging.getInstance().sendEach(messages);
// See the BatchResponse reference documentation
// for the contents of response.
System.out.println(response.getSuccessCount() + " messages were sent successfully");

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// Create a list containing up to 500 messages.
List<Message> messages = Arrays.asList(
    Message.builder()
        .setNotification(Notification.builder()
            .setTitle("Price drop")
            .setBody("5% off all electronics")
            .build())
        .setToken(registrationToken)
        .build(),
    // ...
    Message.builder()
        .setNotification(Notification.builder()
            .setTitle("Price drop")
            .setBody("2% off all books")
            .build())
        .setTopic("readers-club")
        .build()
);

BatchResponse response = FirebaseMessaging.getInstance().sendEach(messages);
// See the BatchResponse reference documentation
// for the contents of response.
System.out.println(response.getSuccessCount() + " messages were sent successfully");

Python

মিশ্র টার্গেট ব্যবহার করা (সাজেস্ট করা):

# Create a list containing up to 500 messages.
messages = [
    messaging.Message(
        notification=messaging.Notification('Price drop', '5% off all electronics'),
        fid='YOUR_REGISTERED_FID', # Using FID (Recommended)
    ),
    messaging.Message(
        notification=messaging.Notification('Price drop', '2% off all books'),
        token='YOUR_REGISTRATION_TOKEN', # Using token (Deprecated)
    ),
    messaging.Message(
        notification=messaging.Notification('Price drop', '10% off all shoes'),
        topic='readers-club',
    ),
]

response = messaging.send_each(messages)
# See the BatchResponse reference documentation
# for the contents of response.
print('{0} messages were sent successfully'.format(response.success_count))

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

# Create a list containing up to 500 messages.
messages = [
    messaging.Message(
        notification=messaging.Notification('Price drop', '5% off all electronics'),
        token=registration_token,
    ),
    # ...
    messaging.Message(
        notification=messaging.Notification('Price drop', '2% off all books'),
        topic='readers-club',
    ),
]

response = messaging.send_each(messages)
# See the BatchResponse reference documentation
# for the contents of response.
print(f'{response.success_count} messages were sent successfully')

Go

মিশ্র টার্গেট ব্যবহার করা (সাজেস্ট করা):

// Create a list containing up to 500 messages.
messages := []*messaging.Message{
    {
        Notification: &messaging.Notification{
            Title: "Price drop",
            Body:  "5% off all electronics",
        },
        Fid: "YOUR_REGISTERED_FID", // Using FID (Recommended)
    },
    {
        Notification: &messaging.Notification{
            Title: "Price drop",
            Body:  "2% off all books",
        },
        Token: "YOUR_REGISTRATION_TOKEN", // Using token (Deprecated)
    },
    {
        Notification: &messaging.Notification{
            Title: "Price drop",
            Body:  "10% off all shoes",
        },
        Topic: "readers-club",
    },
}

br, err := client.SendEach(ctx, messages)
if err != nil {
    log.Fatalln(err)
}
// See the BatchResponse reference documentation
// for the contents of response.
fmt.Printf("%d messages were sent successfully\n", br.SuccessCount)

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

// Create a list containing up to 500 messages.
messages := []*messaging.Message{
	{
		Notification: &messaging.Notification{
			Title: "Price drop",
			Body:  "5% off all electronics",
		},
		Token: registrationToken,
	},
	{
		Notification: &messaging.Notification{
			Title: "Price drop",
			Body:  "2% off all books",
		},
		Topic: "readers-club",
	},
}

br, err := client.SendEach(context.Background(), messages)
if err != nil {
	log.Fatalln(err)
}

// See the BatchResponse reference documentation
// for the contents of response.
fmt.Printf("%d messages were sent successfully\n", br.SuccessCount)

C#

মিশ্র টার্গেট ব্যবহার করা (সাজেস্ট করা):

// Create a list containing up to 500 messages.
var messages = new List<Message>()
{
    new Message()
    {
        Notification = new Notification()
        {
            Title = "Price drop",
            Body = "5% off all electronics",
        },
        Fid = "YOUR_REGISTERED_FID", // Using FID (Recommended)
    },
    new Message()
    {
        Notification = new Notification()
        {
            Title = "Price drop",
            Body = "2% off all books",
        },
        Token = "YOUR_REGISTRATION_TOKEN", // Using token (Deprecated)
    },
    new Message()
    {
        Notification = new Notification()
        {
            Title = "Price drop",
            Body = "10% off all shoes",
        },
        Topic = "readers-club",
    },
};

var response = await FirebaseMessaging.DefaultInstance.SendEachAsync(messages);
// See the BatchResponse reference documentation
// for the contents of response.
Console.WriteLine($"{response.SuccessCount} messages were sent successfully");

রেজিস্ট্রেশন টোকেন ব্যবহার করা (বন্ধ করে দেওয়া হয়েছে):

            // Create a list containing up to 500 messages.
            var messages = new List<Message>()
            {
                new Message()
                {
                    Notification = new Notification()
                    {
                        Title = "Price drop",
                        Body = "5% off all electronics",
                    },
#pragma warning disable CS0618
                    Token = registrationToken,
#pragma warning restore CS0618
                },
                new Message()
                {
                    Notification = new Notification()
                    {
                        Title = "Price drop",
                        Body = "2% off all books",
                    },
                    Topic = "readers-club",
                },
            };

            var response = await FirebaseMessaging.DefaultInstance.SendEachAsync(messages);
            // See the BatchResponse reference documentation
            // for the contents of response.
            Console.WriteLine($"{response.SuccessCount} messages were sent successfully");