অ্যাপ সার্ভার তৈরি করুন অনুরোধ পাঠান

Firebase Admin SDK বা FCM অ্যাপ সার্ভার প্রোটোকল ব্যবহার করে, আপনি বার্তার অনুরোধ তৈরি করতে পারেন এবং সেগুলিকে এই ধরনের লক্ষ্যগুলিতে পাঠাতে পারেন:

  • বিষয়ের নাম
  • অবস্থা
  • ডিভাইস নিবন্ধন টোকেন
  • ডিভাইস গ্রুপের নাম (শুধুমাত্র প্রোটোকল)

আপনি পূর্বনির্ধারিত ক্ষেত্র, আপনার নিজস্ব ব্যবহারকারী-সংজ্ঞায়িত ক্ষেত্রগুলির একটি ডেটা পেলোড বা উভয় ধরনের পেলোড ধারণকারী একটি বার্তা সহ একটি বিজ্ঞপ্তি পেলোড সহ বার্তা পাঠাতে পারেন। আরো তথ্যের জন্য বার্তা প্রকার দেখুন.

Firebase Admin SDK (যেটিতে Node , Java , Python , C# , এবং Go এর জন্য সমর্থন রয়েছে) এবং v1 HTTP প্রোটোকল ব্যবহার করে কীভাবে বিজ্ঞপ্তি বার্তা পাঠাতে হয় এই পৃষ্ঠার উদাহরণগুলি দেখায়৷

নির্দিষ্ট ডিভাইসে বার্তা পাঠান

একটি একক, নির্দিষ্ট ডিভাইসে পাঠাতে, দেখানো হিসাবে ডিভাইসের নিবন্ধন টোকেন পাস করুন। নিবন্ধন টোকেন সম্পর্কে আরও জানতে আপনার প্ল্যাটফর্মের জন্য ক্লায়েন্ট সেটআপ তথ্য দেখুন।

// 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);
  });
// 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().send(message);
// Response is a message ID string.
System.out.println("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)
// 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)
// 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" },
    },
    Token = registrationToken,
};

// 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);
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":{
      "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
      "notification":{
        "body":"This is an FCM notification message!",
        "title":"FCM Message"
      }
   }
}

cURL কমান্ড:

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "notification":{
     "title":"FCM Message",
     "body":"This is an FCM Message"
   },
   "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

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

    {
      "name":"projects/myproject-b5ae1/messages/0:1500415314455276%31bd1c9631bd1c96"
    }

একাধিক ডিভাইসে বার্তা পাঠান

অ্যাডমিন FCM এপিআই আপনাকে ডিভাইস রেজিস্ট্রেশন টোকেনগুলির একটি তালিকায় একটি বার্তা মাল্টিকাস্ট করার অনুমতি দেয়। আপনি প্রতি আহ্বানের জন্য 500টি পর্যন্ত ডিভাইস নিবন্ধন টোকেন নির্দিষ্ট করতে পারেন।

// Create a list containing up to 500 registration tokens.
// 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().sendMulticast(message)
  .then((response) => {
    console.log(response.successCount + ' messages were sent successfully');
  });
// Create a list containing up to 500 registration tokens.
// 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().sendMulticast(message);
// 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 registration tokens.
# 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_multicast(message)
# 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 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.SendMulticast(context.Background(), message)
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 registration tokens.
// 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()
{
    Tokens = registrationTokens,
    Data = new Dictionary<string, string>()
    {
        { "score", "850" },
        { "time", "2:45" },
    },
};

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

রিটার্ন মান হল টোকেনগুলির একটি তালিকা যা ইনপুট টোকেনের ক্রম অনুসারে। আপনি কোন টোকেনগুলির কারণে ত্রুটি হয়েছে তা পরীক্ষা করতে চাইলে এটি কার্যকর।

// 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().sendMulticast(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);
    }
  });
// 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().sendMulticast(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);
}
# 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_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('List of tokens that caused failures: {0}'.format(failed_tokens))
// 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.SendMulticast(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)
}
// 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()
{
    Tokens = registrationTokens,
    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}");
}

বিষয় বার্তা পাঠান

আপনি একটি বিষয় তৈরি করার পরে, হয় ক্লায়েন্ট সাইডের বিষয়ে বা সার্ভার API এর মাধ্যমে ক্লায়েন্ট অ্যাপের দৃষ্টান্ত সাবস্ক্রাইব করে, আপনি বিষয়টিতে বার্তা পাঠাতে পারেন। আপনি যদি প্রথমবার তৈরি করেন FCM জন্য অনুরোধ পাঠান, তাহলে গুরুত্বপূর্ণ পটভূমি এবং সেটআপ তথ্যের জন্য আপনার সার্ভার পরিবেশ এবং FCM নির্দেশিকা দেখুন।

ব্যাকএন্ডে আপনার পাঠানো যুক্তিতে, দেখানো হিসাবে পছন্দসই বিষয়ের নাম উল্লেখ করুন:

// 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);
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 প্রথমে বন্ধনীতে যেকোনো শর্ত মূল্যায়ন করে, এবং তারপর বাম থেকে ডানে অভিব্যক্তি মূল্যায়ন করে। উপরের অভিব্যক্তিতে, কোনো একক বিষয়ে সাবস্ক্রাইব করা ব্যবহারকারী বার্তাটি গ্রহণ করেন না। একইভাবে, যে ব্যবহারকারী TopicA -তে সাবস্ক্রাইব করেন না তিনি বার্তা পাবেন না। এই সংমিশ্রণগুলি এটি গ্রহণ করে:

  • TopicA এবং TopicB
  • TopicA এবং TopicC

আপনি আপনার শর্তসাপেক্ষ অভিব্যক্তিতে পাঁচটি বিষয় পর্যন্ত অন্তর্ভুক্ত করতে পারেন।

একটি শর্তে পাঠাতে:

// 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);
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

ডিভাইস গ্রুপে বার্তা পাঠান

ডিভাইস গ্রুপে বার্তা পাঠাতে, HTTP v1 API ব্যবহার করুন। আপনি যদি বর্তমানে HTTP বা XMPP-এর জন্য অপ্রচলিত লিগ্যাসি সেন্ড API ব্যবহার করে ডিভাইস গোষ্ঠীতে পাঠাচ্ছেন, অথবা উত্তরাধিকার প্রোটোকলের উপর ভিত্তি করে Node.js-এর জন্য Firebase Admin SDK এর পুরনো সংস্করণগুলির যে কোনও একটি ব্যবহার করে, আমরা দৃঢ়ভাবে সুপারিশ করছি যে আপনি দ্রুততম সুযোগে HTTP v1 API-এ স্থানান্তর করুন ৷ 2024 সালের জুনে লিগ্যাসি সেন্ড এপিআই নিষ্ক্রিয় এবং সরানো হবে।

একটি ডিভাইস গ্রুপে বার্তা পাঠানো একটি পৃথক ডিভাইসে বার্তা পাঠানোর অনুরূপ, একই পদ্ধতি ব্যবহার করে প্রেরণের অনুরোধ অনুমোদন করে ৷ গ্রুপ বিজ্ঞপ্তি কী token ক্ষেত্র সেট করুন:

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":{
      "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ",
      "data":{
        "hello": "This is a Firebase Cloud Messaging device group message!"
      }
   }
}
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "data":{
     "hello": "This is a Firebase Cloud Messaging device group message!"
   },
   "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

বার্তা একটি ব্যাচ পাঠান

অ্যাডমিন SDK ব্যাচে বার্তা পাঠানো সমর্থন করে। আপনি একটি একক ব্যাচে 500টি বার্তা পর্যন্ত গোষ্ঠীবদ্ধ করতে পারেন এবং প্রতিটি বার্তার জন্য পৃথক HTTP অনুরোধ পাঠানোর তুলনায় উল্লেখযোগ্য কর্মক্ষমতা উন্নতি সহ একটি একক API কলে সেগুলি পাঠাতে পারেন।

এই বৈশিষ্ট্যটি বার্তাগুলির একটি কাস্টমাইজড সেট তৈরি করতে এবং বিষয় বা নির্দিষ্ট ডিভাইস নিবন্ধন টোকেন সহ বিভিন্ন প্রাপকদের কাছে পাঠাতে ব্যবহার করা যেতে পারে। এই বৈশিষ্ট্যটি ব্যবহার করুন যখন, উদাহরণস্বরূপ, আপনাকে একই সাথে বার্তার অংশে সামান্য ভিন্ন বিবরণ সহ বিভিন্ন শ্রোতাদের কাছে বার্তা পাঠাতে হবে৷

// 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().sendAll(messages)
  .then((response) => {
    console.log(response.successCount + ' 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().sendAll(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.
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_all(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{
			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.SendAll(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)
// 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",
        },
        Token = registrationToken,
    },
    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");

সরাসরি বুট-সক্ষম বার্তা পাঠান (শুধুমাত্র অ্যান্ড্রয়েড)

আপনি HTTP v1 বা লিগ্যাসি HTTP API ব্যবহার করে সরাসরি বুট মোডে ডিভাইসগুলিতে বার্তা পাঠাতে পারেন। সরাসরি বুট মোডে ডিভাইসে পাঠানোর আগে, নিশ্চিত করুন যে আপনি সরাসরি বুট মোডে FCM বার্তা পেতে ক্লায়েন্ট ডিভাইসগুলিকে সক্ষম করার পদক্ষেপগুলি সম্পূর্ণ করেছেন।

FCM v1 HTTP API ব্যবহার করে পাঠান

বার্তার অনুরোধে অবশ্যই "direct_boot_ok" : true অনুরোধের অংশের AndroidConfig বিকল্পগুলিতে সত্য। যেমন:

https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send
Content-Type:application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA

{
  "message":{
    "token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
    "data": {
      "score": "5x1",
      "time": "15:10"
    },
    "android": {
      "direct_boot_ok": true,
    },
}

প্ল্যাটফর্ম জুড়ে বার্তা কাস্টমাইজ করুন

Firebase Admin SDK এবং FCM v1 HTTP প্রোটোকল উভয়ই আপনার বার্তা অনুরোধগুলিকে message অবজেক্টে উপলব্ধ সমস্ত ক্ষেত্র সেট করার অনুমতি দেয়৷ এর মধ্যে রয়েছে:

  • বার্তা প্রাপ্ত সমস্ত অ্যাপ্লিকেশন দৃষ্টান্ত দ্বারা ব্যাখ্যা করা ক্ষেত্রগুলির একটি সাধারণ সেট৷
  • প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলির সেট, যেমন AndroidConfig এবং WebpushConfig , শুধুমাত্র নির্দিষ্ট প্ল্যাটফর্মে চলমান অ্যাপের উদাহরণ দ্বারা ব্যাখ্যা করা হয়।

প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলি আপনাকে বিভিন্ন প্ল্যাটফর্মের জন্য বার্তাগুলি কাস্টমাইজ করার নমনীয়তা দেয় যাতে প্রাপ্তির সময় সেগুলি সঠিকভাবে পরিচালনা করা হয়। FCM ব্যাকএন্ড সমস্ত নির্দিষ্ট পরামিতি বিবেচনা করবে এবং প্রতিটি প্ল্যাটফর্মের জন্য বার্তাটি কাস্টমাইজ করবে।

কখন সাধারণ ক্ষেত্র ব্যবহার করবেন

সাধারণ ক্ষেত্রগুলি ব্যবহার করুন যখন আপনি:

  • অ্যাপল, অ্যান্ড্রয়েড, এবং ওয়েব - সমস্ত প্ল্যাটফর্মে লক্ষ্য করা অ্যাপের উদাহরণ
  • বিষয় বার্তা পাঠানো

সমস্ত অ্যাপ্লিকেশন উদাহরণ, প্ল্যাটফর্ম নির্বিশেষে, নিম্নলিখিত সাধারণ ক্ষেত্রগুলিকে ব্যাখ্যা করতে পারে:

কখন প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র ব্যবহার করবেন

আপনি যখন চান তখন প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র ব্যবহার করুন:

  • শুধুমাত্র নির্দিষ্ট প্ল্যাটফর্মে ক্ষেত্র পাঠান
  • সাধারণ ক্ষেত্র ছাড়াও প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র পাঠান

যখনই আপনি শুধুমাত্র নির্দিষ্ট প্ল্যাটফর্মে মান পাঠাতে চান, সাধারণ ক্ষেত্র ব্যবহার করবেন না ; প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র ব্যবহার করুন। উদাহরণস্বরূপ, শুধুমাত্র Apple প্ল্যাটফর্ম এবং ওয়েবে একটি বিজ্ঞপ্তি পাঠাতে কিন্তু Android এ নয়, আপনাকে অবশ্যই দুটি পৃথক ক্ষেত্র ব্যবহার করতে হবে, একটি Apple এর জন্য এবং একটি ওয়েবের জন্য৷

আপনি যখন নির্দিষ্ট ডেলিভারি অপশন সহ বার্তা পাঠাচ্ছেন, তখন সেগুলি সেট করতে প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলি ব্যবহার করুন৷ আপনি চাইলে প্ল্যাটফর্ম প্রতি বিভিন্ন মান নির্দিষ্ট করতে পারেন। যাইহোক, এমনকি যখন আপনি প্ল্যাটফর্ম জুড়ে অপরিহার্যভাবে একই মান সেট করতে চান, আপনাকে অবশ্যই প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র ব্যবহার করতে হবে। এর কারণ হল প্রতিটি প্ল্যাটফর্ম মানটিকে কিছুটা আলাদাভাবে ব্যাখ্যা করতে পারে—উদাহরণস্বরূপ, Android-এ টাইম-টু-লাইভ সেকেন্ডে মেয়াদ শেষ হওয়ার সময় হিসাবে সেট করা হয়, যখন Apple-এ এটি মেয়াদ শেষ হওয়ার তারিখ হিসাবে সেট করা হয়।

উদাহরণ: রঙ এবং আইকন বিকল্প সহ বিজ্ঞপ্তি বার্তা

এই উদাহরণ প্রেরণের অনুরোধটি সমস্ত প্ল্যাটফর্মে একটি সাধারণ বিজ্ঞপ্তি শিরোনাম এবং সামগ্রী পাঠায়, তবে এটি Android ডিভাইসগুলিতে কিছু প্ল্যাটফর্ম-নির্দিষ্ট ওভাররাইডও পাঠায়।

Android এর জন্য, অনুরোধটি Android ডিভাইসে প্রদর্শনের জন্য একটি বিশেষ আইকন এবং রঙ সেট করে। AndroidNotification- এর রেফারেন্সে যেমন উল্লেখ করা হয়েছে, রঙটি #rrggbb ফরম্যাটে নির্দিষ্ট করা হয়েছে এবং ছবিটি অবশ্যই অ্যান্ড্রয়েড অ্যাপের স্থানীয় আইকন রিসোর্স হতে হবে।

এখানে একজন ব্যবহারকারীর ডিভাইসে ভিজ্যুয়াল এফেক্টের একটি আনুমানিক ধারণা রয়েছে:

দুটি ডিভাইসের সহজ অঙ্কন, একটিতে একটি কাস্টম আইকন এবং রঙ প্রদর্শন করা হয়

const topicName = 'industry-tech';

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.'
  },
  android: {
    notification: {
      icon: 'stock_ticker_update',
      color: '#7e55c3'
    }
  },
  topic: topicName,
};

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);
  });
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())
    .setAndroidConfig(AndroidConfig.builder()
        .setTtl(3600 * 1000)
        .setNotification(AndroidNotification.builder()
            .setIcon("stock_ticker_update")
            .setColor("#f45342")
            .build())
        .build())
    .setApnsConfig(ApnsConfig.builder()
        .setAps(Aps.builder()
            .setBadge(42)
            .build())
        .build())
    .setTopic("industry-tech")
    .build();
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.',
    ),
    android=messaging.AndroidConfig(
        ttl=datetime.timedelta(seconds=3600),
        priority='normal',
        notification=messaging.AndroidNotification(
            icon='stock_ticker_update',
            color='#f45342'
        ),
    ),
    apns=messaging.APNSConfig(
        payload=messaging.APNSPayload(
            aps=messaging.Aps(badge=42),
        ),
    ),
    topic='industry-tech',
)
oneHour := time.Duration(1) * time.Hour
badge := 42
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.",
	},
	Android: &messaging.AndroidConfig{
		TTL: &oneHour,
		Notification: &messaging.AndroidNotification{
			Icon:  "stock_ticker_update",
			Color: "#f45342",
		},
	},
	APNS: &messaging.APNSConfig{
		Payload: &messaging.APNSPayload{
			Aps: &messaging.Aps{
				Badge: &badge,
			},
		},
	},
	Topic: "industry-tech",
}
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.",
    },
    Android = new AndroidConfig()
    {
        TimeToLive = TimeSpan.FromHours(1),
        Notification = new AndroidNotification()
        {
            Icon = "stock_ticker_update",
            Color = "#f45342",
        },
    },
    Apns = new ApnsConfig()
    {
        Aps = new Aps()
        {
            Badge = 42,
        },
    },
    Topic = "industry-tech",
};
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":"industry-tech",
     "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."
     },
     "android":{
       "notification":{
         "icon":"stock_ticker_update",
         "color":"#7e55c3"
       }
     }
   }
 }

বার্তা বডিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলির সম্পূর্ণ বিশদ বিবরণের জন্য HTTP v1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: একটি কাস্টম চিত্র সহ বিজ্ঞপ্তি বার্তা৷

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

একটি প্রদর্শন বিজ্ঞপ্তিতে একটি চিত্রের সহজ অঙ্কন

Node.js বিশ্রাম
const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Sparky says hello!'
  },
  android: {
    notification: {
      imageUrl: 'https://foo.bar.pizza-monster.png'
    }
  },
  apns: {
    payload: {
      aps: {
        'mutable-content': 1
      }
    },
    fcm_options: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  webpush: {
    headers: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  topic: topicName,
};

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);
  });
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":"industry-tech",
     "notification":{
       "title":"Sparky says hello!",
     },
     "android":{
       "notification":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "mutable-content":1
         }
       },
       "fcm_options": {
           "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "webpush":{
       "headers":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     }
   }
 }

বার্তা বডিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলির সম্পূর্ণ বিশদ বিবরণের জন্য HTTP v1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: সংশ্লিষ্ট ক্লিক অ্যাকশন সহ বিজ্ঞপ্তি বার্তা

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

একটি ওয়েব পৃষ্ঠা খোলার জন্য একটি ব্যবহারকারীর ট্যাপের সহজ অঙ্কন৷

Node.js বিশ্রাম
const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Breaking News....'
  },
  android: {
    notification: {
      clickAction: 'news_intent'
    }
  },
  apns: {
    payload: {
      aps: {
        'category': 'INVITE_CATEGORY'
      }
    }
  },
  webpush: {
    fcmOptions: {
      link: 'breakingnews.html'
    }
  },
  topic: topicName,
};

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);
  });
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":"industry-tech",
     "notification":{
       "title":"Breaking News...",
     },
     "android":{
       "notification":{
         "click_action":"news_intent"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "category" : "INVITE_CATEGORY"
         }
       },
     },
     "webpush":{
       "fcm_options":{
         "link":"breakingnews.html"
       }
     }
   }
 }

বার্তা বডিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলির সম্পূর্ণ বিশদ বিবরণের জন্য HTTP v1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: স্থানীয়করণ বিকল্প সহ বিজ্ঞপ্তি বার্তা

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

দুটি ডিভাইসের সহজ অঙ্কন ইংরেজি এবং স্প্যানিশ ভাষায় পাঠ্য প্রদর্শন করে

Node.js বিশ্রাম
var topicName = 'industry-tech';

var message = {
  android: {
    ttl: 3600000,
    notification: {
      bodyLocKey: 'STOCK_NOTIFICATION_BODY',
      bodyLocArgs: ['FooCorp', '11.80', '835.67', '1.43']
    }
  },
  apns: {
    payload: {
      aps: {
        alert: {
          locKey: 'STOCK_NOTIFICATION_BODY',
          locArgs: ['FooCorp', '11.80', '835.67', '1.43']
        }
      }
    }
  },
  topic: topicName,
};

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);
  });
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":"Tech",
             "android":{
               "ttl":"3600s",
               "notification":{
                 "body_loc_key": "STOCK_NOTIFICATION_BODY",
                 "body_loc_args":  ["FooCorp", "11.80", "835.67", "1.43"],
               },
             },
             "apns":{
               "payload":{
                 "aps":{
                   "alert" : {
                     "loc-key": "STOCK_NOTIFICATION_BODY",
                     "loc-args":  ["FooCorp", "11.80", "835.67", "1.43"],
                    },
                 },
               },
             },
  },
}'

বার্তা বডিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলির সম্পূর্ণ বিশদ বিবরণের জন্য HTTP v1 রেফারেন্স ডকুমেন্টেশন দেখুন।

HTTP v1 API-এর জন্য REST ত্রুটি কোড

HTTP v1 API-এর জন্য HTTP ত্রুটি প্রতিক্রিয়াগুলিতে একটি ত্রুটি কোড, একটি ত্রুটি বার্তা এবং ত্রুটির স্থিতি রয়েছে৷ এগুলিতে ত্রুটির আরও বিশদ বিবরণ সহ একটি details অ্যারে থাকতে পারে।

এখানে দুটি নমুনা ত্রুটি প্রতিক্রিয়া আছে:

উদাহরণ 1: একটি ডেটা বার্তায় একটি অবৈধ মান সহ HTTP v1 API অনুরোধ থেকে ত্রুটির প্রতিক্রিয়া

{
  "error": {
    "code": 400,
    "message": "Invalid value at 'message.data[0].value' (TYPE_STRING), 12",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "message.data[0].value",
            "description": "Invalid value at 'message.data[0].value' (TYPE_STRING), 12"
          }
        ]
      }
    ]
  }
}

উদাহরণ 2: একটি অবৈধ রেজিস্ট্রেশন টোকেন সহ HTTP v1 API অনুরোধ থেকে ত্রুটির প্রতিক্রিয়া

{
  "error": {
    "code": 400,
    "message": "The registration token is not a valid FCM registration token",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "INVALID_ARGUMENT"
      }
    ]
   }
}

মনে রাখবেন যে উভয় বার্তার কোড এবং স্থিতি একই, তবে বিবরণ অ্যারেতে বিভিন্ন ধরণের মান রয়েছে। প্রথম উদাহরণে type.googleapis.com/google.rpc.BadRequest টাইপ আছে যা অনুরোধের মানগুলিতে একটি ত্রুটি নির্দেশ করে৷ type.googleapis.com/google.firebase.fcm.v1.FcmError টাইপের দ্বিতীয় উদাহরণে একটি FCM নির্দিষ্ট ত্রুটি রয়েছে। অনেক ত্রুটির জন্য, বিশদ অ্যারেতে এমন তথ্য রয়েছে যা আপনাকে ডিবাগ করতে এবং একটি রেজোলিউশন খুঁজতে হবে।

নিম্নলিখিত সারণী FCM v1 REST API ত্রুটি কোড এবং তাদের বিবরণ তালিকাভুক্ত করে।

ত্রুটি কোড বর্ণনা এবং সমাধান পদক্ষেপ
UNSPECIFIED_ERROR এই ত্রুটি সম্পর্কে আর কোন তথ্য উপলব্ধ নেই৷ কোনোটিই নয়।
INVALID_ARGUMENT (HTTP ত্রুটি কোড = 400) অনুরোধের প্যারামিটারগুলি অবৈধ ছিল৷ কোন ক্ষেত্রটি অবৈধ ছিল তা নির্দিষ্ট করতে google.rpc.BadRequest টাইপের একটি এক্সটেনশন ফেরত দেওয়া হয়৷ সম্ভাব্য কারণগুলির মধ্যে রয়েছে অবৈধ নিবন্ধন, অবৈধ প্যাকেজের নাম, বার্তাটি খুব বড়, অবৈধ ডেটা কী, অবৈধ TTL বা অন্যান্য অবৈধ প্যারামিটার৷
অবৈধ রেজিস্ট্রেশন : আপনি সার্ভারে যে রেজিস্ট্রেশন টোকেন পাস করবেন তার ফরম্যাট চেক করুন। নিশ্চিত করুন যে এটি FCM এর সাথে নিবন্ধন করার সময় ক্লায়েন্ট অ্যাপটি প্রাপ্ত নিবন্ধন টোকেনের সাথে মেলে। টোকেন কাটবেন না বা অতিরিক্ত অক্ষর যোগ করবেন না।
অবৈধ প্যাকেজের নাম : নিশ্চিত করুন যে বার্তাটি একটি নিবন্ধন টোকেনে সম্বোধন করা হয়েছে যার প্যাকেজের নাম অনুরোধে পাস করা মানের সাথে মেলে।
বার্তাটি খুব বড় : একটি বার্তায় অন্তর্ভুক্ত পেলোড ডেটার মোট আকার FCM সীমা অতিক্রম না করে তা পরীক্ষা করুন: বেশিরভাগ বার্তার জন্য 4096 বাইট, বা বিষয়গুলিতে বার্তাগুলির ক্ষেত্রে 2048 বাইট৷ এটি কী এবং মান উভয়ই অন্তর্ভুক্ত করে।
অবৈধ ডেটা কী : চেক করুন যে পেলোড ডেটাতে কোনও কী (যেমন থেকে, বা জিসিএম, বা google দ্বারা প্রিফিক্স করা কোনও মান) নেই যা FCM দ্বারা অভ্যন্তরীণভাবে ব্যবহৃত হয়৷ মনে রাখবেন কিছু শব্দ (যেমন collapse_key) FCM দ্বারাও ব্যবহার করা হয় কিন্তু পেলোডে অনুমোদিত, এই ক্ষেত্রে পেলোড মান FCM মান দ্বারা ওভাররাইড করা হবে।
অবৈধ TTL : চেক করুন যে ttl-এ ব্যবহৃত মানটি 0 এবং 2,419,200 (4 সপ্তাহ) এর মধ্যে সেকেন্ডে একটি পূর্ণসংখ্যা উপস্থাপন করে।
অবৈধ প্যারামিটার : প্রদত্ত পরামিতিগুলির সঠিক নাম এবং প্রকার আছে কিনা তা পরীক্ষা করুন৷
UNREGISTERED (HTTP ত্রুটি কোড = 404) অ্যাপ ইনস্ট্যান্স FCM থেকে নিবন্ধনহীন ছিল। এর মানে সাধারণত ব্যবহৃত টোকেন আর বৈধ নয় এবং একটি নতুন ব্যবহার করতে হবে। এই ত্রুটি অনুপস্থিত নিবন্ধন টোকেন, বা অনিবন্ধিত টোকেন দ্বারা সৃষ্ট হতে পারে.
অনুপস্থিত নিবন্ধন : যদি বার্তার লক্ষ্য একটি token মান হয়, তবে অনুরোধটিতে একটি নিবন্ধন টোকেন রয়েছে কিনা তা পরীক্ষা করুন।
নিবন্ধিত নয় : একটি বিদ্যমান নিবন্ধন টোকেন বেশ কয়েকটি পরিস্থিতিতে বৈধ না হতে পারে, যার মধ্যে রয়েছে:
- যদি ক্লায়েন্ট অ্যাপটি FCM-এর সাথে নিবন্ধন না করে।
- যদি ক্লায়েন্ট অ্যাপটি স্বয়ংক্রিয়ভাবে অনিবন্ধিত হয়, যা ঘটতে পারে যদি ব্যবহারকারী অ্যাপ্লিকেশনটি আনইনস্টল করে। উদাহরণস্বরূপ, iOS-এ, যদি APNs ফিডব্যাক পরিষেবা APNs টোকেনটিকে অবৈধ বলে রিপোর্ট করে।
- যদি রেজিস্ট্রেশন টোকেনের মেয়াদ শেষ হয়ে যায় (উদাহরণস্বরূপ, Google রেজিস্ট্রেশন টোকেন রিফ্রেশ করার সিদ্ধান্ত নিতে পারে বা iOS ডিভাইসের জন্য APNs টোকেনের মেয়াদ শেষ হয়ে গেছে)।
- যদি ক্লায়েন্ট অ্যাপটি আপডেট করা হয় কিন্তু নতুন সংস্করণটি বার্তা গ্রহণের জন্য কনফিগার করা না থাকে।
এই সমস্ত ক্ষেত্রে, অ্যাপ সার্ভার থেকে এই নিবন্ধন টোকেনটি সরান এবং বার্তা পাঠানোর জন্য এটি ব্যবহার করা বন্ধ করুন৷
SENDER_ID_MISMATCH (HTTP ত্রুটি কোড = 403) প্রমাণীকৃত প্রেরক আইডি নিবন্ধন টোকেনের জন্য প্রেরক আইডি থেকে আলাদা। একটি নিবন্ধন টোকেন প্রেরকদের একটি নির্দিষ্ট গোষ্ঠীর সাথে আবদ্ধ। যখন একটি ক্লায়েন্ট অ্যাপ FCM-এর জন্য নিবন্ধন করে, তখন এটি অবশ্যই উল্লেখ করবে যে কোন প্রেরকদের বার্তা পাঠানোর অনুমতি দেওয়া হয়েছে। ক্লায়েন্ট অ্যাপে বার্তা পাঠানোর সময় আপনার সেই প্রেরক আইডিগুলির মধ্যে একটি ব্যবহার করা উচিত। আপনি যদি অন্য প্রেরকের কাছে যান, বিদ্যমান নিবন্ধন টোকেনগুলি কাজ করবে না৷
QUOTA_EXCEEDED (HTTP ত্রুটি কোড = 429) বার্তা লক্ষ্যের জন্য প্রেরণের সীমা অতিক্রম করেছে৷ কোন কোটা অতিক্রম করেছে তা নির্দিষ্ট করতে google.rpc.QuotaFailure টাইপের একটি এক্সটেনশন ফেরত দেওয়া হয়। এই ত্রুটিটি বার্তা হারের কোটা অতিক্রম করে, ডিভাইসের বার্তা হারের কোটা অতিক্রম করে বা বিষয় বার্তা হারের কোটা অতিক্রম করার কারণে হতে পারে৷
বার্তার হার অতিক্রম করেছে : বার্তা পাঠানোর হার খুব বেশি। আপনি যে সামগ্রিক হারে বার্তা পাঠান তা আপনাকে অবশ্যই কমাতে হবে। প্রত্যাখ্যান করা বার্তাগুলি পুনরায় চেষ্টা করতে 1 মিনিটের ন্যূনতম প্রাথমিক বিলম্বের সাথে সূচকীয় ব্যাকঅফ ব্যবহার করুন৷
ডিভাইসের বার্তা হার অতিক্রম করেছে : একটি নির্দিষ্ট ডিভাইসে বার্তার হার খুব বেশি। একটি একক ডিভাইসে বার্তা হারের সীমা দেখুন । এই ডিভাইসে প্রেরিত বার্তার সংখ্যা হ্রাস করুন এবং পুনরায় পাঠানোর চেষ্টা করতে সূচকীয় ব্যাকঅফ ব্যবহার করুন৷
বিষয় বার্তার হার অতিক্রম করেছে : একটি নির্দিষ্ট বিষয়ের সদস্যদের কাছে বার্তার হার খুব বেশি৷ এই বিষয়ের জন্য প্রেরিত বার্তার সংখ্যা হ্রাস করুন এবং পুনরায় পাঠানোর চেষ্টা করতে 1 মিনিটের ন্যূনতম প্রাথমিক বিলম্বের সাথে সূচকীয় ব্যাকঅফ ব্যবহার করুন।
UNAVAILABLE (HTTP ত্রুটি কোড = 503) সার্ভারটি ওভারলোড হয়েছে৷ সার্ভার সময়মত অনুরোধ প্রক্রিয়া করতে পারেনি. একই অনুরোধ পুনরায় চেষ্টা করুন, কিন্তু আপনি অবশ্যই:
- যদি এটি FCM সংযোগ সার্ভারের প্রতিক্রিয়াতে অন্তর্ভুক্ত করা হয় তবে পুনরায় চেষ্টা-পরবর্তী শিরোনামটিকে সম্মান করুন৷
- আপনার পুনরায় চেষ্টা করার পদ্ধতিতে সূচকীয় ব্যাকঅফ প্রয়োগ করুন। (যেমন আপনি যদি প্রথম পুনঃপ্রচেষ্টার আগে এক সেকেন্ড অপেক্ষা করেন, তাহলে পরেরটির আগে কমপক্ষে দুই সেকেন্ড অপেক্ষা করুন, তারপরে 4 সেকেন্ড এবং আরও অনেক কিছু)। আপনি যদি একাধিক বার্তা পাঠান, তাহলে ঝাঁকুনি প্রয়োগ করার কথা বিবেচনা করুন। আরও তথ্যের জন্য, পুনঃপ্রচারগুলি হ্যান্ডলিং দেখুন , বা FCM স্থিতির ড্যাশবোর্ড পরীক্ষা করে শনাক্ত করতে যে কোনও চলমান পরিষেবার ব্যাঘাত FCM প্রভাবিত করছে কিনা। যেসব প্রেরক সমস্যা সৃষ্টি করে তাদের অস্বীকৃত হওয়ার ঝুঁকি থাকে।
INTERNAL (HTTP ত্রুটি কোড = 500) একটি অজানা অভ্যন্তরীণ ত্রুটি ঘটেছে৷ অনুরোধটি প্রক্রিয়া করার চেষ্টা করার সময় সার্ভার একটি ত্রুটির সম্মুখীন হয়েছে৷ আপনি পুনরায় চেষ্টা পরিচালনা করা বা FCM স্ট্যাটাস ড্যাশবোর্ড চেক করার পরামর্শ অনুসরণ করে একই অনুরোধ পুনরায় চেষ্টা করতে পারেন। FCM কে প্রভাবিত করে এমন কোন চলমান পরিষেবা ব্যাহত হচ্ছে কিনা তা সনাক্ত করতে। যদি ত্রুটি অব্যাহত থাকে, অনুগ্রহ করে Firebase সহায়তার সাথে যোগাযোগ করুন।
THIRD_PARTY_AUTH_ERROR (HTTP ত্রুটি কোড = 401) APNs শংসাপত্র বা ওয়েব পুশ প্রমাণ কী অবৈধ বা অনুপস্থিত ছিল৷ একটি iOS ডিভাইস বা একটি ওয়েব পুশ নিবন্ধন লক্ষ্য করে একটি বার্তা পাঠানো যাবে না. আপনার উন্নয়ন এবং উত্পাদন শংসাপত্রের বৈধতা পরীক্ষা করুন.

অ্যাডমিন ত্রুটি কোড

নিম্নলিখিত সারণীতে Firebase অ্যাডমিন FCM API ত্রুটি কোড এবং তাদের বর্ণনা, প্রস্তাবিত রেজোলিউশন পদক্ষেপ সহ তালিকাভুক্ত করা হয়েছে।

ত্রুটি কোড বর্ণনা এবং সমাধান পদক্ষেপ
messaging/invalid-argument একটি FCM পদ্ধতিতে একটি অবৈধ যুক্তি প্রদান করা হয়েছে৷ ত্রুটি বার্তা অতিরিক্ত তথ্য থাকা উচিত.
messaging/invalid-recipient উদ্দেশ্য বার্তা প্রাপক অবৈধ. ত্রুটি বার্তা অতিরিক্ত তথ্য থাকা উচিত.
messaging/invalid-payload একটি অবৈধ বার্তা পেলোড অবজেক্ট প্রদান করা হয়েছে৷ ত্রুটি বার্তা অতিরিক্ত তথ্য থাকা উচিত.
messaging/invalid-data-payload-key ডেটা বার্তা পেলোডে একটি অবৈধ কী রয়েছে৷ সীমাবদ্ধ কীগুলির জন্য DataMessagePayload এর রেফারেন্স ডকুমেন্টেশন দেখুন।
messaging/payload-size-limit-exceeded প্রদত্ত বার্তা পেলোড FCM আকারের সীমা অতিক্রম করেছে৷ বেশিরভাগ বার্তার জন্য সীমা 4096 বাইট। বিষয়গুলিতে পাঠানো বার্তাগুলির জন্য, সীমা হল 2048 বাইট৷ মোট পেলোড আকারে কী এবং মান উভয়ই অন্তর্ভুক্ত থাকে।
messaging/invalid-options একটি অবৈধ বার্তা বিকল্প অবজেক্ট প্রদান করা হয়েছে. ত্রুটি বার্তা অতিরিক্ত তথ্য থাকা উচিত.
messaging/invalid-registration-token অবৈধ নিবন্ধন টোকেন প্রদান করা হয়েছে. নিশ্চিত করুন যে এটি FCM এর সাথে নিবন্ধন করার সময় ক্লায়েন্ট অ্যাপটি প্রাপ্ত নিবন্ধন টোকেনের সাথে মেলে৷ ছেঁটে ফেলবেন না বা এতে অতিরিক্ত অক্ষর যোগ করবেন না।
messaging/registration-token-not-registered প্রদত্ত নিবন্ধন টোকেন নিবন্ধিত নয়। একটি পূর্বে বৈধ নিবন্ধন টোকেন বিভিন্ন কারণে অনিবন্ধিত হতে পারে, যার মধ্যে রয়েছে:
  • ক্লায়েন্ট অ্যাপটি FCM থেকে নিজেকে অনিবন্ধিত করেছে।
  • ক্লায়েন্ট অ্যাপটি স্বয়ংক্রিয়ভাবে নিবন্ধনমুক্ত ছিল। এটি ঘটতে পারে যদি ব্যবহারকারী অ্যাপ্লিকেশনটি আনইনস্টল করেন বা, Apple প্ল্যাটফর্মে, যদি APNs ফিডব্যাক পরিষেবা APNs টোকেনটিকে অবৈধ হিসাবে রিপোর্ট করে।
  • নিবন্ধন টোকেন মেয়াদ শেষ হয়েছে. উদাহরণস্বরূপ, Google রেজিস্ট্রেশন টোকেনগুলি রিফ্রেশ করার সিদ্ধান্ত নিতে পারে বা Apple ডিভাইসগুলির জন্য APN টোকেনের মেয়াদ শেষ হয়ে যেতে পারে৷
  • ক্লায়েন্ট অ্যাপটি আপডেট করা হয়েছে, কিন্তু নতুন সংস্করণটি বার্তা পাওয়ার জন্য কনফিগার করা হয়নি।
এই সমস্ত ক্ষেত্রে, এই নিবন্ধন টোকেনটি সরান এবং বার্তা পাঠানোর জন্য এটি ব্যবহার করা বন্ধ করুন৷
messaging/invalid-package-name বার্তাটি একটি রেজিস্ট্রেশন টোকেনে সম্বোধন করা হয়েছিল যার প্যাকেজের নাম প্রদত্ত restrictedPackageName বিকল্পের সাথে মেলে না।
messaging/message-rate-exceeded একটি নির্দিষ্ট লক্ষ্যে বার্তার হার খুব বেশি। এই ডিভাইস বা বিষয়ে প্রেরিত বার্তার সংখ্যা হ্রাস করুন এবং অবিলম্বে এই লক্ষ্যে পাঠানোর পুনরায় চেষ্টা করবেন না।
messaging/device-message-rate-exceeded একটি নির্দিষ্ট ডিভাইসে বার্তার হার খুব বেশি। এই ডিভাইসে পাঠানো বার্তার সংখ্যা কমিয়ে দিন এবং অবিলম্বে এই ডিভাইসে পাঠানোর চেষ্টা করবেন না।
messaging/topics-message-rate-exceeded একটি নির্দিষ্ট বিষয়ে গ্রাহকদের বার্তার হার খুব বেশি। এই বিষয়ের জন্য প্রেরিত বার্তার সংখ্যা হ্রাস করুন, এবং অবিলম্বে এই বিষয়ে পুনরায় পাঠানোর চেষ্টা করবেন না।
messaging/too-many-topics একটি রেজিস্ট্রেশন টোকেন সর্বাধিক সংখ্যক বিষয়ে সাবস্ক্রাইব করা হয়েছে এবং আর কোন সাবস্ক্রাইব করা যাবে না।
messaging/invalid-apns-credentials একটি Apple ডিভাইসে লক্ষ্য করা একটি বার্তা পাঠানো যায়নি কারণ প্রয়োজনীয় APNs SSL শংসাপত্র আপলোড করা হয়নি বা মেয়াদ শেষ হয়ে গেছে৷ আপনার বিকাশ এবং উত্পাদন শংসাপত্রের বৈধতা পরীক্ষা করুন।
messaging/mismatched-credential এই SDK প্রমাণীকরণের জন্য ব্যবহৃত শংসাপত্রের প্রদত্ত রেজিস্ট্রেশন টোকেনের সাথে সংশ্লিষ্ট ডিভাইসে বার্তা পাঠানোর অনুমতি নেই। নিশ্চিত করুন যে শংসাপত্র এবং নিবন্ধন টোকেন উভয়ই একই Firebase প্রকল্পের অন্তর্গত। কিভাবে Firebase Admin SDK গুলিকে প্রমাণীকরণ করতে হয় তার ডকুমেন্টেশনের জন্য আপনার অ্যাপে Firebase যোগ করুন দেখুন।
messaging/authentication-error SDK FCM সার্ভারে প্রমাণীকরণ করতে পারেনি৷ নিশ্চিত করুন যে আপনি একটি শংসাপত্র সহ Firebase Admin SDK প্রমাণীকরণ করেছেন যাতে FCM বার্তা পাঠানোর উপযুক্ত অনুমতি রয়েছে৷ কিভাবে Firebase Admin SDK গুলিকে প্রমাণীকরণ করতে হয় তার ডকুমেন্টেশনের জন্য আপনার অ্যাপে Firebase যোগ করুন দেখুন।
messaging/server-unavailable FCM সার্ভার সময়মত অনুরোধ প্রক্রিয়া করতে পারেনি৷ আপনার একই অনুরোধ পুনরায় চেষ্টা করা উচিত, তবে আপনাকে অবশ্যই:
  • Retry-After শিরোনামটিকে সম্মান করুন যদি এটি FCM সংযোগ সার্ভারের প্রতিক্রিয়াতে অন্তর্ভুক্ত থাকে।
  • আপনার পুনরায় চেষ্টা করার পদ্ধতিতে সূচকীয় ব্যাক-অফ প্রয়োগ করুন। উদাহরণস্বরূপ, আপনি যদি প্রথম পুনঃপ্রচেষ্টার আগে এক সেকেন্ড অপেক্ষা করেন, তাহলে পরেরটির আগে কমপক্ষে দুই সেকেন্ড অপেক্ষা করুন, তারপরে চার সেকেন্ড, ইত্যাদি। আপনি যদি একাধিক বার্তা পাঠান, একই সময়ে সমস্ত বার্তার জন্য একটি নতুন অনুরোধ জারি করা এড়াতে প্রতিটিকে একটি অতিরিক্ত র্যান্ডম পরিমাণে স্বাধীনভাবে বিলম্বিত করুন।
যেসব প্রেরক সমস্যা সৃষ্টি করে তাদের কালো তালিকাভুক্ত হওয়ার ঝুঁকি থাকে।
messaging/internal-error অনুরোধটি প্রক্রিয়া করার চেষ্টা করার সময় FCM সার্ভার একটি ত্রুটির সম্মুখীন হয়েছে৷ উপরের messaging/server-unavailable সারিতে তালিকাভুক্ত প্রয়োজনীয়তাগুলি অনুসরণ করে আপনি একই অনুরোধটি পুনরায় চেষ্টা করতে পারেন। ত্রুটি অব্যাহত থাকলে, আমাদের বাগ রিপোর্ট সমর্থন চ্যানেলে সমস্যাটি রিপোর্ট করুন।
messaging/unknown-error একটি অজানা সার্ভার ত্রুটি ফিরে এসেছে. আরো বিস্তারিত জানার জন্য ত্রুটি বার্তায় কাঁচা সার্ভার প্রতিক্রিয়া দেখুন. আপনি যদি এই ত্রুটিটি পান, দয়া করে সম্পূর্ণ ত্রুটি বার্তাটি আমাদের বাগ রিপোর্ট সমর্থন চ্যানেলে রিপোর্ট করুন৷
,

Firebase Admin SDK বা FCM অ্যাপ সার্ভার প্রোটোকল ব্যবহার করে, আপনি বার্তার অনুরোধ তৈরি করতে পারেন এবং সেগুলিকে এই ধরনের লক্ষ্যগুলিতে পাঠাতে পারেন:

  • বিষয়ের নাম
  • অবস্থা
  • ডিভাইস নিবন্ধন টোকেন
  • ডিভাইস গ্রুপের নাম (শুধুমাত্র প্রোটোকল)

আপনি পূর্বনির্ধারিত ক্ষেত্র, আপনার নিজস্ব ব্যবহারকারী-সংজ্ঞায়িত ক্ষেত্রগুলির একটি ডেটা পেলোড বা উভয় ধরনের পেলোড ধারণকারী একটি বার্তা সহ একটি বিজ্ঞপ্তি পেলোড সহ বার্তা পাঠাতে পারেন। আরো তথ্যের জন্য বার্তা প্রকার দেখুন.

Firebase Admin SDK (যেটিতে Node , Java , Python , C# , এবং Go এর জন্য সমর্থন রয়েছে) এবং v1 HTTP প্রোটোকল ব্যবহার করে কীভাবে বিজ্ঞপ্তি বার্তা পাঠাতে হয় এই পৃষ্ঠার উদাহরণগুলি দেখায়৷

নির্দিষ্ট ডিভাইসে বার্তা পাঠান

একটি একক, নির্দিষ্ট ডিভাইসে পাঠাতে, দেখানো হিসাবে ডিভাইসের নিবন্ধন টোকেন পাস করুন। নিবন্ধন টোকেন সম্পর্কে আরও জানতে আপনার প্ল্যাটফর্মের জন্য ক্লায়েন্ট সেটআপ তথ্য দেখুন।

// 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);
  });
// 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().send(message);
// Response is a message ID string.
System.out.println("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)
// 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)
// 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" },
    },
    Token = registrationToken,
};

// 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);
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":{
      "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
      "notification":{
        "body":"This is an FCM notification message!",
        "title":"FCM Message"
      }
   }
}

cURL কমান্ড:

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "notification":{
     "title":"FCM Message",
     "body":"This is an FCM Message"
   },
   "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

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

    {
      "name":"projects/myproject-b5ae1/messages/0:1500415314455276%31bd1c9631bd1c96"
    }

একাধিক ডিভাইসে বার্তা পাঠান

অ্যাডমিন FCM এপিআই আপনাকে ডিভাইস রেজিস্ট্রেশন টোকেনগুলির একটি তালিকায় একটি বার্তা মাল্টিকাস্ট করার অনুমতি দেয়। আপনি প্রতি আহ্বানের জন্য 500টি পর্যন্ত ডিভাইস নিবন্ধন টোকেন নির্দিষ্ট করতে পারেন।

// Create a list containing up to 500 registration tokens.
// 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().sendMulticast(message)
  .then((response) => {
    console.log(response.successCount + ' messages were sent successfully');
  });
// Create a list containing up to 500 registration tokens.
// 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().sendMulticast(message);
// 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 registration tokens.
# 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_multicast(message)
# 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 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.SendMulticast(context.Background(), message)
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 registration tokens.
// 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()
{
    Tokens = registrationTokens,
    Data = new Dictionary<string, string>()
    {
        { "score", "850" },
        { "time", "2:45" },
    },
};

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

রিটার্ন মান হল টোকেনগুলির একটি তালিকা যা ইনপুট টোকেনের ক্রম অনুসারে। আপনি কোন টোকেনগুলির কারণে ত্রুটি হয়েছে তা পরীক্ষা করতে চাইলে এটি কার্যকর।

// 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().sendMulticast(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);
    }
  });
// 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().sendMulticast(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);
}
# 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_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('List of tokens that caused failures: {0}'.format(failed_tokens))
// 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.SendMulticast(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)
}
// 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()
{
    Tokens = registrationTokens,
    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}");
}

বিষয় বার্তা পাঠান

আপনি একটি বিষয় তৈরি করার পরে, হয় ক্লায়েন্ট সাইডের বিষয়ে বা সার্ভার API এর মাধ্যমে ক্লায়েন্ট অ্যাপের দৃষ্টান্ত সাবস্ক্রাইব করে, আপনি বিষয়টিতে বার্তা পাঠাতে পারেন। আপনি যদি প্রথমবার তৈরি করেন FCM জন্য অনুরোধ পাঠান, তাহলে গুরুত্বপূর্ণ পটভূমি এবং সেটআপ তথ্যের জন্য আপনার সার্ভার পরিবেশ এবং FCM নির্দেশিকা দেখুন।

ব্যাকএন্ডে আপনার পাঠানো যুক্তিতে, দেখানো হিসাবে পছন্দসই বিষয়ের নাম উল্লেখ করুন:

// 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);
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 প্রথমে বন্ধনীতে যেকোনো শর্ত মূল্যায়ন করে, এবং তারপর বাম থেকে ডানে অভিব্যক্তি মূল্যায়ন করে। উপরের অভিব্যক্তিতে, কোনো একক বিষয়ে সাবস্ক্রাইব করা ব্যবহারকারী বার্তাটি গ্রহণ করেন না। একইভাবে, যে ব্যবহারকারী TopicA -তে সাবস্ক্রাইব করেন না তিনি বার্তা পাবেন না। এই সংমিশ্রণগুলি এটি গ্রহণ করে:

  • TopicA এবং TopicB
  • TopicA এবং TopicC

আপনি আপনার শর্তাধীন অভিব্যক্তিতে পাঁচটি বিষয় পর্যন্ত অন্তর্ভুক্ত করতে পারেন।

একটি শর্তে পাঠাতে:

// 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);
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

ডিভাইস গ্রুপে বার্তা পাঠান

ডিভাইস গ্রুপে বার্তা পাঠাতে, HTTP v1 API ব্যবহার করুন। আপনি যদি বর্তমানে HTTP বা XMPP-এর জন্য অপ্রচলিত লিগ্যাসি সেন্ড API ব্যবহার করে ডিভাইস গোষ্ঠীতে পাঠাচ্ছেন, অথবা উত্তরাধিকার প্রোটোকলের উপর ভিত্তি করে Node.js-এর জন্য Firebase Admin SDK এর পুরনো সংস্করণগুলির যে কোনও একটি ব্যবহার করে, আমরা দৃঢ়ভাবে সুপারিশ করছি যে আপনি দ্রুততম সুযোগে HTTP v1 API-এ স্থানান্তর করুন ৷ 2024 সালের জুনে লিগ্যাসি সেন্ড এপিআই নিষ্ক্রিয় এবং সরানো হবে।

একটি ডিভাইস গ্রুপে বার্তা পাঠানো একটি পৃথক ডিভাইসে বার্তা পাঠানোর অনুরূপ, একই পদ্ধতি ব্যবহার করে প্রেরণের অনুরোধ অনুমোদন করে ৷ গ্রুপ বিজ্ঞপ্তি কী token ক্ষেত্র সেট করুন:

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":{
      "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ",
      "data":{
        "hello": "This is a Firebase Cloud Messaging device group message!"
      }
   }
}
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "data":{
     "hello": "This is a Firebase Cloud Messaging device group message!"
   },
   "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

বার্তা একটি ব্যাচ পাঠান

অ্যাডমিন SDK ব্যাচে বার্তা পাঠানো সমর্থন করে। আপনি একটি একক ব্যাচে 500টি বার্তা পর্যন্ত গোষ্ঠীবদ্ধ করতে পারেন এবং প্রতিটি বার্তার জন্য পৃথক HTTP অনুরোধ পাঠানোর তুলনায় উল্লেখযোগ্য কর্মক্ষমতা উন্নতি সহ একটি একক API কলে সেগুলি পাঠাতে পারেন।

এই বৈশিষ্ট্যটি বার্তাগুলির একটি কাস্টমাইজড সেট তৈরি করতে এবং বিষয় বা নির্দিষ্ট ডিভাইস নিবন্ধন টোকেন সহ বিভিন্ন প্রাপকদের কাছে পাঠাতে ব্যবহার করা যেতে পারে। এই বৈশিষ্ট্যটি ব্যবহার করুন যখন, উদাহরণস্বরূপ, আপনাকে একই সাথে বার্তার অংশে সামান্য ভিন্ন বিবরণ সহ বিভিন্ন শ্রোতাদের কাছে বার্তা পাঠাতে হবে৷

// 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().sendAll(messages)
  .then((response) => {
    console.log(response.successCount + ' 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().sendAll(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.
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_all(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{
			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.SendAll(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)
// 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",
        },
        Token = registrationToken,
    },
    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");

সরাসরি বুট-সক্ষম বার্তা পাঠান (শুধুমাত্র অ্যান্ড্রয়েড)

আপনি HTTP v1 বা লিগ্যাসি HTTP API ব্যবহার করে সরাসরি বুট মোডে ডিভাইসগুলিতে বার্তা পাঠাতে পারেন। সরাসরি বুট মোডে ডিভাইসে পাঠানোর আগে, নিশ্চিত করুন যে আপনি সরাসরি বুট মোডে FCM বার্তা পেতে ক্লায়েন্ট ডিভাইসগুলিকে সক্ষম করার পদক্ষেপগুলি সম্পূর্ণ করেছেন।

FCM v1 HTTP API ব্যবহার করে পাঠান

বার্তার অনুরোধে অবশ্যই "direct_boot_ok" : true অনুরোধের অংশের AndroidConfig বিকল্পগুলিতে সত্য। যেমন:

https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send
Content-Type:application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA

{
  "message":{
    "token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
    "data": {
      "score": "5x1",
      "time": "15:10"
    },
    "android": {
      "direct_boot_ok": true,
    },
}

প্ল্যাটফর্ম জুড়ে বার্তা কাস্টমাইজ করুন

Firebase Admin SDK এবং FCM v1 HTTP প্রোটোকল উভয়ই আপনার বার্তা অনুরোধগুলিকে message অবজেক্টে উপলব্ধ সমস্ত ক্ষেত্র সেট করার অনুমতি দেয়৷ এর মধ্যে রয়েছে:

  • বার্তা প্রাপ্ত সমস্ত অ্যাপ্লিকেশন দৃষ্টান্ত দ্বারা ব্যাখ্যা করা ক্ষেত্রগুলির একটি সাধারণ সেট৷
  • প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলির সেট, যেমন AndroidConfig এবং WebpushConfig , শুধুমাত্র নির্দিষ্ট প্ল্যাটফর্মে চলমান অ্যাপের উদাহরণ দ্বারা ব্যাখ্যা করা হয়।

প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলি আপনাকে বিভিন্ন প্ল্যাটফর্মের জন্য বার্তাগুলি কাস্টমাইজ করার নমনীয়তা দেয় যাতে প্রাপ্তির সময় সেগুলি সঠিকভাবে পরিচালনা করা হয়। FCM ব্যাকএন্ড সমস্ত নির্দিষ্ট পরামিতি বিবেচনা করবে এবং প্রতিটি প্ল্যাটফর্মের জন্য বার্তাটি কাস্টমাইজ করবে।

কখন সাধারণ ক্ষেত্র ব্যবহার করবেন

সাধারণ ক্ষেত্রগুলি ব্যবহার করুন যখন আপনি:

  • অ্যাপল, অ্যান্ড্রয়েড, এবং ওয়েব - সমস্ত প্ল্যাটফর্মে লক্ষ্য করা অ্যাপের উদাহরণ
  • বিষয় বার্তা পাঠানো

সমস্ত অ্যাপ্লিকেশন উদাহরণ, প্ল্যাটফর্ম নির্বিশেষে, নিম্নলিখিত সাধারণ ক্ষেত্রগুলিকে ব্যাখ্যা করতে পারে:

কখন প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র ব্যবহার করবেন

আপনি যখন চান তখন প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র ব্যবহার করুন:

  • শুধুমাত্র নির্দিষ্ট প্ল্যাটফর্মে ক্ষেত্র পাঠান
  • সাধারণ ক্ষেত্র ছাড়াও প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র পাঠান

যখনই আপনি শুধুমাত্র নির্দিষ্ট প্ল্যাটফর্মে মান পাঠাতে চান, সাধারণ ক্ষেত্র ব্যবহার করবেন না ; প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র ব্যবহার করুন। উদাহরণস্বরূপ, শুধুমাত্র Apple প্ল্যাটফর্ম এবং ওয়েবে একটি বিজ্ঞপ্তি পাঠাতে কিন্তু Android এ নয়, আপনাকে অবশ্যই দুটি পৃথক ক্ষেত্র ব্যবহার করতে হবে, একটি Apple এর জন্য এবং একটি ওয়েবের জন্য৷

আপনি যখন নির্দিষ্ট ডেলিভারি অপশন সহ বার্তা পাঠাচ্ছেন, তখন সেগুলি সেট করতে প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলি ব্যবহার করুন৷ আপনি চাইলে প্ল্যাটফর্ম প্রতি বিভিন্ন মান নির্দিষ্ট করতে পারেন। যাইহোক, এমনকি যখন আপনি প্ল্যাটফর্ম জুড়ে অপরিহার্যভাবে একই মান সেট করতে চান, আপনাকে অবশ্যই প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্র ব্যবহার করতে হবে। এর কারণ হল প্রতিটি প্ল্যাটফর্ম মানটিকে কিছুটা আলাদাভাবে ব্যাখ্যা করতে পারে—উদাহরণস্বরূপ, Android-এ টাইম-টু-লাইভ সেকেন্ডে মেয়াদ শেষ হওয়ার সময় হিসাবে সেট করা হয়, যখন Apple-এ এটি মেয়াদ শেষ হওয়ার তারিখ হিসাবে সেট করা হয়।

উদাহরণ: রঙ এবং আইকন বিকল্প সহ বিজ্ঞপ্তি বার্তা

এই উদাহরণ প্রেরণের অনুরোধটি সমস্ত প্ল্যাটফর্মে একটি সাধারণ বিজ্ঞপ্তি শিরোনাম এবং সামগ্রী পাঠায়, তবে এটি Android ডিভাইসগুলিতে কিছু প্ল্যাটফর্ম-নির্দিষ্ট ওভাররাইডও পাঠায়।

Android এর জন্য, অনুরোধটি Android ডিভাইসে প্রদর্শনের জন্য একটি বিশেষ আইকন এবং রঙ সেট করে। AndroidNotification- এর রেফারেন্সে যেমন উল্লেখ করা হয়েছে, রঙটি #rrggbb ফরম্যাটে নির্দিষ্ট করা হয়েছে এবং ছবিটি অবশ্যই অ্যান্ড্রয়েড অ্যাপের স্থানীয় আইকন রিসোর্স হতে হবে।

এখানে একজন ব্যবহারকারীর ডিভাইসে ভিজ্যুয়াল এফেক্টের একটি আনুমানিক ধারণা রয়েছে:

দুটি ডিভাইসের সহজ অঙ্কন, একটিতে একটি কাস্টম আইকন এবং রঙ প্রদর্শন করা হয়

const topicName = 'industry-tech';

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.'
  },
  android: {
    notification: {
      icon: 'stock_ticker_update',
      color: '#7e55c3'
    }
  },
  topic: topicName,
};

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);
  });
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())
    .setAndroidConfig(AndroidConfig.builder()
        .setTtl(3600 * 1000)
        .setNotification(AndroidNotification.builder()
            .setIcon("stock_ticker_update")
            .setColor("#f45342")
            .build())
        .build())
    .setApnsConfig(ApnsConfig.builder()
        .setAps(Aps.builder()
            .setBadge(42)
            .build())
        .build())
    .setTopic("industry-tech")
    .build();
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.',
    ),
    android=messaging.AndroidConfig(
        ttl=datetime.timedelta(seconds=3600),
        priority='normal',
        notification=messaging.AndroidNotification(
            icon='stock_ticker_update',
            color='#f45342'
        ),
    ),
    apns=messaging.APNSConfig(
        payload=messaging.APNSPayload(
            aps=messaging.Aps(badge=42),
        ),
    ),
    topic='industry-tech',
)
oneHour := time.Duration(1) * time.Hour
badge := 42
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.",
	},
	Android: &messaging.AndroidConfig{
		TTL: &oneHour,
		Notification: &messaging.AndroidNotification{
			Icon:  "stock_ticker_update",
			Color: "#f45342",
		},
	},
	APNS: &messaging.APNSConfig{
		Payload: &messaging.APNSPayload{
			Aps: &messaging.Aps{
				Badge: &badge,
			},
		},
	},
	Topic: "industry-tech",
}
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.",
    },
    Android = new AndroidConfig()
    {
        TimeToLive = TimeSpan.FromHours(1),
        Notification = new AndroidNotification()
        {
            Icon = "stock_ticker_update",
            Color = "#f45342",
        },
    },
    Apns = new ApnsConfig()
    {
        Aps = new Aps()
        {
            Badge = 42,
        },
    },
    Topic = "industry-tech",
};
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":"industry-tech",
     "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."
     },
     "android":{
       "notification":{
         "icon":"stock_ticker_update",
         "color":"#7e55c3"
       }
     }
   }
 }

বার্তা বডিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলির সম্পূর্ণ বিশদ বিবরণের জন্য HTTP v1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: একটি কাস্টম চিত্র সহ বিজ্ঞপ্তি বার্তা৷

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

একটি প্রদর্শন বিজ্ঞপ্তিতে একটি চিত্রের সহজ অঙ্কন

Node.js বিশ্রাম
const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Sparky says hello!'
  },
  android: {
    notification: {
      imageUrl: 'https://foo.bar.pizza-monster.png'
    }
  },
  apns: {
    payload: {
      aps: {
        'mutable-content': 1
      }
    },
    fcm_options: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  webpush: {
    headers: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  topic: topicName,
};

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);
  });
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":"industry-tech",
     "notification":{
       "title":"Sparky says hello!",
     },
     "android":{
       "notification":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "mutable-content":1
         }
       },
       "fcm_options": {
           "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "webpush":{
       "headers":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     }
   }
 }

বার্তা বডিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলির সম্পূর্ণ বিশদ বিবরণের জন্য HTTP v1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: সংশ্লিষ্ট ক্লিক অ্যাকশন সহ বিজ্ঞপ্তি বার্তা

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

একটি ওয়েব পৃষ্ঠা খোলার জন্য একটি ব্যবহারকারীর ট্যাপের সহজ অঙ্কন৷

Node.js বিশ্রাম
const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Breaking News....'
  },
  android: {
    notification: {
      clickAction: 'news_intent'
    }
  },
  apns: {
    payload: {
      aps: {
        'category': 'INVITE_CATEGORY'
      }
    }
  },
  webpush: {
    fcmOptions: {
      link: 'breakingnews.html'
    }
  },
  topic: topicName,
};

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);
  });
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":"industry-tech",
     "notification":{
       "title":"Breaking News...",
     },
     "android":{
       "notification":{
         "click_action":"news_intent"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "category" : "INVITE_CATEGORY"
         }
       },
     },
     "webpush":{
       "fcm_options":{
         "link":"breakingnews.html"
       }
     }
   }
 }

বার্তা বডিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলির সম্পূর্ণ বিশদ বিবরণের জন্য HTTP v1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: স্থানীয়করণ বিকল্প সহ বিজ্ঞপ্তি বার্তা

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

দুটি ডিভাইসের সহজ অঙ্কন ইংরেজি এবং স্প্যানিশ ভাষায় পাঠ্য প্রদর্শন করে

Node.js বিশ্রাম
var topicName = 'industry-tech';

var message = {
  android: {
    ttl: 3600000,
    notification: {
      bodyLocKey: 'STOCK_NOTIFICATION_BODY',
      bodyLocArgs: ['FooCorp', '11.80', '835.67', '1.43']
    }
  },
  apns: {
    payload: {
      aps: {
        alert: {
          locKey: 'STOCK_NOTIFICATION_BODY',
          locArgs: ['FooCorp', '11.80', '835.67', '1.43']
        }
      }
    }
  },
  topic: topicName,
};

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);
  });
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":"Tech",
             "android":{
               "ttl":"3600s",
               "notification":{
                 "body_loc_key": "STOCK_NOTIFICATION_BODY",
                 "body_loc_args":  ["FooCorp", "11.80", "835.67", "1.43"],
               },
             },
             "apns":{
               "payload":{
                 "aps":{
                   "alert" : {
                     "loc-key": "STOCK_NOTIFICATION_BODY",
                     "loc-args":  ["FooCorp", "11.80", "835.67", "1.43"],
                    },
                 },
               },
             },
  },
}'

বার্তা বডিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলির সম্পূর্ণ বিশদ বিবরণের জন্য HTTP v1 রেফারেন্স ডকুমেন্টেশন দেখুন।

HTTP v1 API-এর জন্য REST ত্রুটি কোড

HTTP v1 API-এর জন্য HTTP ত্রুটি প্রতিক্রিয়াগুলিতে একটি ত্রুটি কোড, একটি ত্রুটি বার্তা এবং ত্রুটির স্থিতি রয়েছে৷ এগুলিতে ত্রুটির আরও বিশদ বিবরণ সহ একটি details অ্যারে থাকতে পারে।

এখানে দুটি নমুনা ত্রুটি প্রতিক্রিয়া আছে:

উদাহরণ 1: একটি ডেটা বার্তায় একটি অবৈধ মান সহ HTTP v1 API অনুরোধ থেকে ত্রুটির প্রতিক্রিয়া৷

{
  "error": {
    "code": 400,
    "message": "Invalid value at 'message.data[0].value' (TYPE_STRING), 12",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "message.data[0].value",
            "description": "Invalid value at 'message.data[0].value' (TYPE_STRING), 12"
          }
        ]
      }
    ]
  }
}

উদাহরণ 2: একটি অবৈধ রেজিস্ট্রেশন টোকেন সহ HTTP v1 API অনুরোধ থেকে ত্রুটির প্রতিক্রিয়া

{
  "error": {
    "code": 400,
    "message": "The registration token is not a valid FCM registration token",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "INVALID_ARGUMENT"
      }
    ]
   }
}

মনে রাখবেন যে উভয় বার্তার কোড এবং স্থিতি একই, তবে বিবরণ অ্যারেতে বিভিন্ন ধরণের মান রয়েছে। প্রথম উদাহরণে type.googleapis.com/google.rpc.BadRequest টাইপ আছে যা অনুরোধের মানগুলিতে একটি ত্রুটি নির্দেশ করে৷ type.googleapis.com/google.firebase.fcm.v1.FcmError টাইপের দ্বিতীয় উদাহরণে একটি FCM নির্দিষ্ট ত্রুটি রয়েছে। অনেক ত্রুটির জন্য, বিশদ অ্যারেতে এমন তথ্য রয়েছে যা আপনাকে ডিবাগ করতে এবং একটি রেজোলিউশন খুঁজতে হবে।

নিম্নলিখিত সারণী FCM v1 REST API ত্রুটি কোড এবং তাদের বিবরণ তালিকাভুক্ত করে।

ত্রুটি কোড বর্ণনা এবং সমাধান পদক্ষেপ
UNSPECIFIED_ERROR এই ত্রুটি সম্পর্কে আর কোনও তথ্য উপলব্ধ নেই। কোনোটিই নয়।
INVALID_ARGUMENT (এইচটিটিপি ত্রুটি কোড = 400) অনুরোধ পরামিতিগুলি অবৈধ ছিল। কোন ক্ষেত্রটি অবৈধ ছিল তা নির্দিষ্ট করতে google.rpc.BadRequest সম্ভাব্য কারণগুলির মধ্যে অবৈধ নিবন্ধকরণ, অবৈধ প্যাকেজের নাম, বার্তা খুব বড়, অবৈধ ডেটা কী, অবৈধ টিটিএল বা অন্যান্য অবৈধ পরামিতি অন্তর্ভুক্ত রয়েছে।
অবৈধ নিবন্ধকরণ : আপনি সার্ভারে পাস করা রেজিস্ট্রেশন টোকেনের ফর্ম্যাটটি পরীক্ষা করুন। নিশ্চিত হয়ে নিন যে এটি ক্লায়েন্ট অ্যাপ্লিকেশনটি এফসিএম -এর সাথে নিবন্ধকরণ থেকে প্রাপ্ত রেজিস্ট্রেশন টোকেনের সাথে মেলে। টোকেন কাটা বা অতিরিক্ত অক্ষর যুক্ত করবেন না।
অবৈধ প্যাকেজের নাম : নিশ্চিত হয়ে নিন যে বার্তাটি একটি নিবন্ধকরণ টোকেনের সাথে সম্বোধন করা হয়েছে যার প্যাকেজের নামটি অনুরোধে পাস করা মানের সাথে মেলে।
বার্তা খুব বড় : পরীক্ষা করুন যে কোনও বার্তায় অন্তর্ভুক্ত পে -লোড ডেটার মোট আকার এফসিএম সীমা ছাড়িয়ে যায় না: বেশিরভাগ বার্তার জন্য 4096 বাইট বা বিষয়গুলিতে বার্তাগুলির ক্ষেত্রে 2048 বাইট। এর মধ্যে কী এবং মান উভয়ই অন্তর্ভুক্ত রয়েছে।
অবৈধ ডেটা কী : পে -লোড ডেটাতে কোনও কী নেই (যেমন থেকে, বা জিসিএম, বা গুগল দ্বারা উপসর্গযুক্ত কোনও মান) যা এফসিএম দ্বারা অভ্যন্তরীণভাবে ব্যবহৃত হয়। নোট করুন যে কিছু শব্দ (যেমন ধসফেস_কি) এফসিএম দ্বারাও ব্যবহৃত হয় তবে পে -লোডে অনুমোদিত হয়, সেক্ষেত্রে পে -লোড মানটি এফসিএম মান দ্বারা ওভাররাইড করা হবে।
অবৈধ টিটিএল : টিটিএলে ব্যবহৃত মানটি একটি পূর্ণসংখ্যা যা 0 থেকে 2,419,200 (4 সপ্তাহ) এর মধ্যে সেকেন্ডে সময়কাল উপস্থাপন করে।
অবৈধ পরামিতি : প্রদত্ত পরামিতিগুলির সঠিক নাম এবং প্রকার রয়েছে কিনা তা পরীক্ষা করে দেখুন।
UNREGISTERED (এইচটিটিপি ত্রুটি কোড = 404) অ্যাপ্লিকেশন উদাহরণটি এফসিএম থেকে নিবন্ধভুক্ত ছিল। এর সাধারণত অর্থ হ'ল ব্যবহৃত টোকেনটি আর বৈধ নয় এবং একটি নতুন ব্যবহার করতে হবে। এই ত্রুটিটি রেজিস্ট্রেশন টোকেন বা নিবন্ধভুক্ত টোকেনগুলি অনুপস্থিত কারণে হতে পারে।
অনুপস্থিত নিবন্ধকরণ : যদি বার্তার লক্ষ্যটি একটি token মান হয় তবে অনুরোধটিতে একটি নিবন্ধকরণ টোকেন রয়েছে তা পরীক্ষা করুন।
নিবন্ধিত নয় : একটি বিদ্যমান রেজিস্ট্রেশন টোকেন বেশ কয়েকটি পরিস্থিতিতে বৈধ হতে বন্ধ করতে পারে, সহ:
- যদি ক্লায়েন্ট অ্যাপটি এফসিএম দিয়ে নিবন্ধভুক্ত করে।
- যদি ক্লায়েন্ট অ্যাপ্লিকেশনটি স্বয়ংক্রিয়ভাবে নিবন্ধভুক্ত হয়, যা ব্যবহারকারী যদি অ্যাপ্লিকেশনটি আনইনস্টল করে তবে ঘটতে পারে। উদাহরণস্বরূপ, আইওএস -এ, যদি এপিএনএস প্রতিক্রিয়া পরিষেবা এপিএনএস টোকেনটিকে অবৈধ হিসাবে রিপোর্ট করে।
- যদি নিবন্ধকরণ টোকেনের মেয়াদ শেষ হয় (উদাহরণস্বরূপ, গুগল রেজিস্ট্রেশন টোকেনগুলি রিফ্রেশ করার সিদ্ধান্ত নিতে পারে, বা আইওএস ডিভাইসের জন্য এপিএনএস টোকেনটির মেয়াদ শেষ হয়ে গেছে)।
- যদি ক্লায়েন্ট অ্যাপটি আপডেট করা হয় তবে নতুন সংস্করণটি বার্তা পাওয়ার জন্য কনফিগার করা হয় না।
এই সমস্ত ক্ষেত্রে, অ্যাপ্লিকেশন সার্ভার থেকে এই নিবন্ধকরণ টোকেনটি সরান এবং বার্তাগুলি প্রেরণে এটি ব্যবহার বন্ধ করুন।
SENDER_ID_MISMATCH (এইচটিটিপি ত্রুটি কোড = 403) অনুমোদিত প্রেরক আইডি নিবন্ধকরণ টোকেনের জন্য প্রেরক আইডি থেকে পৃথক। একটি রেজিস্ট্রেশন টোকেন প্রেরকের একটি নির্দিষ্ট গ্রুপের সাথে আবদ্ধ। যখন কোনও ক্লায়েন্ট অ্যাপ এফসিএমের জন্য নিবন্ধভুক্ত করে, এটি অবশ্যই নির্দিষ্ট করতে হবে যে কোন প্রেরকদের বার্তা প্রেরণের অনুমতি দেওয়া হয়েছে। ক্লায়েন্ট অ্যাপে বার্তা প্রেরণ করার সময় আপনার সেই প্রেরক আইডিগুলির মধ্যে একটি ব্যবহার করা উচিত। আপনি যদি অন্য কোনও প্রেরকের কাছে স্যুইচ করেন তবে বিদ্যমান রেজিস্ট্রেশন টোকেনগুলি কাজ করবে না।
QUOTA_EXCEEDED (এইচটিটিপি ত্রুটি কোড = 429) বার্তা লক্ষ্যমাত্রার জন্য প্রেরণ সীমা ছাড়িয়ে গেছে। কোন কোটা ছাড়িয়ে গেছে তা নির্দিষ্ট করতে google.rpc.QuotaFailure টাইপের একটি এক্সটেনশন ফিরে আসে। এই ত্রুটিটি অতিক্রম করা বার্তা রেট কোটা, ছাড়িয়ে যাওয়া ডিভাইস বার্তা রেট কোটা বা টপিক মেসেজ রেট কোটা ছাড়িয়ে যেতে পারে।
বার্তার হার ছাড়িয়ে গেছে : বার্তা প্রেরণের হার খুব বেশি। আপনি অবশ্যই বার্তা প্রেরণ করতে হবে সামগ্রিক হার হ্রাস করতে হবে। প্রত্যাখ্যানিত বার্তাগুলি পুনরায় চেষ্টা করতে ন্যূনতম প্রাথমিক বিলম্বের সাথে এক্সফোনেনশিয়াল ব্যাকঅফ ব্যবহার করুন।
ডিভাইস বার্তার হার ছাড়িয়ে গেছে : একটি নির্দিষ্ট ডিভাইসে বার্তাগুলির হার খুব বেশি। একটি একক ডিভাইসে বার্তা রেট সীমা দেখুন । এই ডিভাইসে প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং পুনরায় চেষ্টা করার জন্য সূচকীয় ব্যাকঅফ ব্যবহার করুন।
বিষয় বার্তার হার ছাড়িয়ে গেছে : কোনও নির্দিষ্ট বিষয়ের গ্রাহকদের কাছে বার্তাগুলির হার খুব বেশি। এই বিষয়ের জন্য প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং পুনরায় চেষ্টা করার জন্য ন্যূনতম প্রাথমিক বিলম্বের সাথে এক্সফোনেনশিয়াল ব্যাকঅফ ব্যবহার করুন।
UNAVAILABLE (এইচটিটিপি ত্রুটি কোড = 503) সার্ভারটি ওভারলোড হয়েছে। সার্ভার সময়মতো অনুরোধটি প্রক্রিয়া করতে পারেনি। একই অনুরোধটি আবার চেষ্টা করুন, তবে আপনাকে অবশ্যই:
- যদি এফসিএম সংযোগ সার্ভারের প্রতিক্রিয়াতে অন্তর্ভুক্ত থাকে তবে পুনরায় চেষ্টা-গ্রহণের শিরোনামকে সম্মান করুন।
- আপনার পুনরায় চেষ্টা পদ্ধতিতে ক্ষতিকারক ব্যাকঅফ প্রয়োগ করুন। (যেমন আপনি যদি প্রথম পুনরায় চেষ্টা করার আগে এক সেকেন্ড অপেক্ষা করেন তবে পরেরটির আগে কমপক্ষে দুই সেকেন্ড অপেক্ষা করুন, তারপরে 4 সেকেন্ড এবং আরও কিছু)। আপনি যদি একাধিক বার্তা প্রেরণ করছেন তবে জিটারিং প্রয়োগ করার বিষয়টি বিবেচনা করুন। আরও তথ্যের জন্য, হ্যান্ডলিং রিট্রিগুলি দেখুন , বা এফসিএমকে প্রভাবিত করে এমন কোনও চলমান পরিষেবা বাধা রয়েছে কিনা তা সনাক্ত করতে এফসিএম স্ট্যাটাস ড্যাশবোর্ডটি পরীক্ষা করুন। প্রেরকরা যে সমস্যাগুলি অস্বচ্ছল হওয়ার ঝুঁকি নিয়ে আসে।
INTERNAL (এইচটিটিপি ত্রুটি কোড = 500) একটি অজানা অভ্যন্তরীণ ত্রুটি ঘটেছে। অনুরোধটি প্রক্রিয়া করার চেষ্টা করার সময় সার্ভারটি একটি ত্রুটির মুখোমুখি হয়েছিল। আপনি পুনরুদ্ধার পরিচালনা করতে বা এফসিএম স্ট্যাটাস ড্যাশবোর্ড পরীক্ষা করার পরামর্শের পরে একই অনুরোধটি পুনরায় চেষ্টা করতে পারেন। এফসিএমকে প্রভাবিত করে এমন কোনও চলমান পরিষেবা বাধা রয়েছে কিনা তা সনাক্ত করতে। যদি ত্রুটিটি অব্যাহত থাকে তবে দয়া করে ফায়ারবেস সমর্থনের সাথে যোগাযোগ করুন।
THIRD_PARTY_AUTH_ERROR (এইচটিটিপি ত্রুটি কোড = 401) এপিএনএস শংসাপত্র বা ওয়েব পুশ এথ কীটি অবৈধ বা অনুপস্থিত ছিল। আইওএস ডিভাইস বা একটি ওয়েব পুশ নিবন্ধকরণকে লক্ষ্যযুক্ত একটি বার্তা প্রেরণ করা যায়নি। আপনার বিকাশ এবং উত্পাদন শংসাপত্রগুলির বৈধতা পরীক্ষা করুন।

অ্যাডমিন ত্রুটি কোড

নিম্নলিখিত টেবিলটি ফায়ারবেস অ্যাডমিন FCM এপিআই ত্রুটি কোডগুলি এবং তাদের বিবরণগুলি প্রস্তাবিত রেজোলিউশন পদক্ষেপগুলি সহ তালিকাভুক্ত করে।

ত্রুটি কোড বর্ণনা এবং রেজোলিউশন পদক্ষেপ
messaging/invalid-argument একটি FCM পদ্ধতিতে একটি অবৈধ যুক্তি সরবরাহ করা হয়েছিল। ত্রুটি বার্তায় অতিরিক্ত তথ্য থাকা উচিত।
messaging/invalid-recipient উদ্দেশ্যযুক্ত বার্তা প্রাপক অবৈধ। ত্রুটি বার্তায় অতিরিক্ত তথ্য থাকা উচিত।
messaging/invalid-payload একটি অবৈধ বার্তা পে -লোড অবজেক্ট সরবরাহ করা হয়েছিল। ত্রুটি বার্তায় অতিরিক্ত তথ্য থাকা উচিত।
messaging/invalid-data-payload-key ডেটা বার্তা পে -লোডে একটি অবৈধ কী রয়েছে। সীমাবদ্ধ কীগুলির জন্য DataMessagePayload জন্য রেফারেন্স ডকুমেন্টেশন দেখুন।
messaging/payload-size-limit-exceeded প্রদত্ত বার্তা পে -লোড FCM আকারের সীমা ছাড়িয়ে গেছে। সীমাটি বেশিরভাগ বার্তাগুলির জন্য 4096 বাইট। বিষয়গুলিতে প্রেরিত বার্তাগুলির জন্য, সীমাটি 2048 বাইট। মোট পে -লোড আকারে কী এবং মান উভয়ই অন্তর্ভুক্ত।
messaging/invalid-options একটি অবৈধ বার্তা বিকল্প অবজেক্ট সরবরাহ করা হয়েছিল। ত্রুটি বার্তায় অতিরিক্ত তথ্য থাকা উচিত।
messaging/invalid-registration-token অবৈধ নিবন্ধকরণ টোকেন সরবরাহ করা হয়েছে। নিশ্চিত হয়ে নিন যে এটি ক্লায়েন্ট অ্যাপ্লিকেশনটি FCM সাথে নিবন্ধকরণ থেকে প্রাপ্ত রেজিস্ট্রেশন টোকেনের সাথে মেলে। এতে অতিরিক্ত অক্ষর কাটা বা যুক্ত করবেন না।
messaging/registration-token-not-registered প্রদত্ত রেজিস্ট্রেশন টোকেন নিবন্ধিত নয়। পূর্বে বৈধ রেজিস্ট্রেশন টোকেন বিভিন্ন কারণে নিবন্ধভুক্ত করা যেতে পারে, সহ:
  • ক্লায়েন্ট অ্যাপটি FCM থেকে নিজেকে নিবন্ধভুক্ত করেছে।
  • ক্লায়েন্ট অ্যাপ্লিকেশনটি স্বয়ংক্রিয়ভাবে নিবন্ধভুক্ত ছিল। যদি ব্যবহারকারী অ্যাপ্লিকেশনটি আনইনস্টল করে বা অ্যাপল প্ল্যাটফর্মগুলিতে, যদি এপিএনএস প্রতিক্রিয়া পরিষেবাটি এপিএনএস টোকেনটিকে অবৈধ হিসাবে রিপোর্ট করে।
  • রেজিস্ট্রেশন টোকেনের মেয়াদ শেষ হয়ে গেছে। উদাহরণস্বরূপ, গুগল নিবন্ধকরণ টোকেনগুলি রিফ্রেশ করার সিদ্ধান্ত নিতে পারে বা অ্যাপএনএস টোকেন অ্যাপল ডিভাইসগুলির জন্য মেয়াদোত্তীর্ণ হতে পারে।
  • ক্লায়েন্ট অ্যাপটি আপডেট করা হয়েছিল, তবে নতুন সংস্করণটি বার্তাগুলি পাওয়ার জন্য কনফিগার করা হয়নি।
এই সমস্ত ক্ষেত্রে, এই নিবন্ধকরণ টোকেন সরান এবং বার্তা প্রেরণের জন্য এটি ব্যবহার বন্ধ করুন।
messaging/invalid-package-name বার্তাটি একটি নিবন্ধকরণ টোকেনকে সম্বোধন করা হয়েছিল যার প্যাকেজের নাম সরবরাহিত restrictedPackageName বিকল্পের সাথে মেলে না।
messaging/message-rate-exceeded একটি নির্দিষ্ট লক্ষ্যে বার্তাগুলির হার খুব বেশি। এই ডিভাইস বা বিষয়টিতে প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং তাত্ক্ষণিকভাবে এই লক্ষ্যটিতে প্রেরণ পুনরায় চেষ্টা করবেন না।
messaging/device-message-rate-exceeded একটি নির্দিষ্ট ডিভাইসে বার্তাগুলির হার খুব বেশি। এই ডিভাইসে প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং তাত্ক্ষণিকভাবে এই ডিভাইসে প্রেরণ পুনরায় চেষ্টা করবেন না।
messaging/topics-message-rate-exceeded কোনও নির্দিষ্ট বিষয়ের গ্রাহকদের কাছে বার্তাগুলির হার খুব বেশি। এই বিষয়টির জন্য প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং তাত্ক্ষণিকভাবে এই বিষয়টিতে প্রেরণ পুনরায় চেষ্টা করবেন না।
messaging/too-many-topics একটি রেজিস্ট্রেশন টোকেন সর্বাধিক সংখ্যক বিষয়ের সাবস্ক্রাইব করা হয়েছে এবং আর কোনও সাবস্ক্রাইব করা যাবে না।
messaging/invalid-apns-credentials কোনও অ্যাপল ডিভাইসে লক্ষ্যযুক্ত একটি বার্তা প্রেরণ করা যায়নি কারণ প্রয়োজনীয় এপিএনএস এসএসএল শংসাপত্রটি আপলোড করা হয়নি বা মেয়াদ শেষ হয়ে গেছে। আপনার বিকাশ এবং উত্পাদন শংসাপত্রগুলির বৈধতা পরীক্ষা করুন।
messaging/mismatched-credential এই এসডিকে প্রমাণীকরণের জন্য ব্যবহৃত শংসাপত্রের সরবরাহিত নিবন্ধকরণ টোকেনের সাথে সম্পর্কিত ডিভাইসে বার্তা প্রেরণের অনুমতি নেই। নিশ্চিত করুন যে শংসাপত্র এবং নিবন্ধকরণ টোকেন উভয়ই একই ফায়ারবেস প্রকল্পের অন্তর্গত। কীভাবে Firebase Admin SDK এসকে প্রমাণীকরণ করবেন সে সম্পর্কে ডকুমেন্টেশনের জন্য আপনার অ্যাপ্লিকেশনটিতে ফায়ারবেস যুক্ত করুন
messaging/authentication-error এসডিকে FCM সার্ভারগুলিতে প্রমাণীকরণ করতে পারেনি। নিশ্চিত হয়ে নিন যে আপনি Firebase Admin SDK একটি শংসাপত্রের সাথে প্রমাণীকরণ করেছেন যা FCM বার্তা প্রেরণের উপযুক্ত অনুমতি রয়েছে। কীভাবে Firebase Admin SDK এসকে প্রমাণীকরণ করবেন সে সম্পর্কে ডকুমেন্টেশনের জন্য আপনার অ্যাপ্লিকেশনটিতে ফায়ারবেস যুক্ত করুন
messaging/server-unavailable FCM সার্ভার সময়মতো অনুরোধটি প্রক্রিয়া করতে পারেনি। আপনার একই অনুরোধটি আবার চেষ্টা করা উচিত, তবে আপনাকে অবশ্যই:
  • যদি এটি FCM সংযোগ সার্ভারের প্রতিক্রিয়াতে অন্তর্ভুক্ত থাকে তবে Retry-After শিরোনামকে সম্মান করুন।
  • আপনার পুনরায় চেষ্টা পদ্ধতিতে তাত্পর্যপূর্ণ ব্যাক-অফ প্রয়োগ করুন। উদাহরণস্বরূপ, আপনি যদি প্রথম পুনরায় চেষ্টা করার আগে এক সেকেন্ড অপেক্ষা করেন তবে পরেরটির আগে কমপক্ষে দুই সেকেন্ড অপেক্ষা করুন, তারপরে চার সেকেন্ড এবং আরও অনেক কিছু। আপনি যদি একাধিক বার্তা প্রেরণ করছেন, একই সাথে সমস্ত বার্তাগুলির জন্য নতুন অনুরোধ জারি করা এড়াতে অতিরিক্ত এলোমেলো পরিমাণে প্রত্যেককে স্বাধীনভাবে বিলম্ব করুন।
প্রেরকরা যে সমস্যাগুলি কালো তালিকাভুক্ত হওয়ার ঝুঁকি নিয়ে আসে।
messaging/internal-error অনুরোধটি প্রক্রিয়া করার চেষ্টা করার সময় FCM সার্ভার একটি ত্রুটির মুখোমুখি হয়েছিল। আপনি উপরের messaging/server-unavailable সারিতে তালিকাভুক্ত প্রয়োজনীয়তা অনুসরণ করে একই অনুরোধটি আবার চেষ্টা করতে পারেন। যদি ত্রুটিটি অব্যাহত থাকে তবে দয়া করে আমাদের বাগ রিপোর্ট সমর্থন চ্যানেলে সমস্যাটি রিপোর্ট করুন।
messaging/unknown-error একটি অজানা সার্ভার ত্রুটি ফিরে এসেছিল। আরও তথ্যের জন্য ত্রুটি বার্তায় কাঁচা সার্ভারের প্রতিক্রিয়া দেখুন। আপনি যদি এই ত্রুটিটি পান তবে দয়া করে আমাদের বাগ রিপোর্ট সমর্থন চ্যানেলে সম্পূর্ণ ত্রুটি বার্তাটি রিপোর্ট করুন।
,

Firebase Admin SDK বা FCM অ্যাপ্লিকেশন সার্ভার প্রোটোকলগুলি ব্যবহার করে আপনি বার্তা অনুরোধগুলি তৈরি করতে পারেন এবং এগুলি এই ধরণের লক্ষ্যগুলিতে প্রেরণ করতে পারেন:

  • বিষয়ের নাম
  • অবস্থা
  • ডিভাইস নিবন্ধকরণ টোকেন
  • ডিভাইস গ্রুপের নাম (কেবল প্রোটোকল)

আপনি পূর্বনির্ধারিত ক্ষেত্রগুলি, আপনার নিজের ব্যবহারকারী-সংজ্ঞায়িত ক্ষেত্রগুলির ডেটা পেডলোড বা উভয় ধরণের পে-লোডযুক্ত একটি বার্তা সহ বার্তা পাঠাতে পারেন। আরও তথ্যের জন্য বার্তার ধরণগুলি দেখুন।

এই পৃষ্ঠার উদাহরণগুলি দেখায় যে কীভাবে Firebase Admin SDK (যা নোড , জাভা , পাইথন , সি# , এবং জিও এর জন্য সমর্থন রয়েছে) এবং ভি 1 এইচটিটিপি প্রোটোকল ব্যবহার করে কীভাবে বিজ্ঞপ্তি বার্তা প্রেরণ করবেন।

নির্দিষ্ট ডিভাইসে বার্তা প্রেরণ করুন

একটি একক, নির্দিষ্ট ডিভাইসে প্রেরণ করতে, ডিভাইসের নিবন্ধকরণ টোকেনটি দেখানো হিসাবে পাস করুন। নিবন্ধকরণ টোকেন সম্পর্কে আরও জানতে আপনার প্ল্যাটফর্মের জন্য ক্লায়েন্ট সেটআপ তথ্য দেখুন।

// 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);
  });
// 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().send(message);
// Response is a message ID string.
System.out.println("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)
// 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)
// 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" },
    },
    Token = registrationToken,
};

// 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);
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":{
      "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
      "notification":{
        "body":"This is an FCM notification message!",
        "title":"FCM Message"
      }
   }
}

কার্ল কমান্ড:

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "notification":{
     "title":"FCM Message",
     "body":"This is an FCM Message"
   },
   "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

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

    {
      "name":"projects/myproject-b5ae1/messages/0:1500415314455276%31bd1c9631bd1c96"
    }

একাধিক ডিভাইসে বার্তা প্রেরণ করুন

অ্যাডমিন FCM এপিআইগুলি আপনাকে ডিভাইস রেজিস্ট্রেশন টোকেনের তালিকায় একটি বার্তা মাল্টিকাস্ট করার অনুমতি দেয়। আপনি অনুরোধ অনুযায়ী 500 টি পর্যন্ত ডিভাইস রেজিস্ট্রেশন টোকেন নির্দিষ্ট করতে পারেন।

// Create a list containing up to 500 registration tokens.
// 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().sendMulticast(message)
  .then((response) => {
    console.log(response.successCount + ' messages were sent successfully');
  });
// Create a list containing up to 500 registration tokens.
// 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().sendMulticast(message);
// 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 registration tokens.
# 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_multicast(message)
# 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 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.SendMulticast(context.Background(), message)
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 registration tokens.
// 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()
{
    Tokens = registrationTokens,
    Data = new Dictionary<string, string>()
    {
        { "score", "850" },
        { "time", "2:45" },
    },
};

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

রিটার্ন মানটি টোকেনের একটি তালিকা যা ইনপুট টোকেনের ক্রমের সাথে মিলে যায়। আপনি যখন কোন টোকেনগুলির ত্রুটিগুলি ঘটেছে তা যাচাই করতে চান তখন এটি দরকারী।

// 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().sendMulticast(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);
    }
  });
// 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().sendMulticast(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);
}
# 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_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('List of tokens that caused failures: {0}'.format(failed_tokens))
// 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.SendMulticast(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)
}
// 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()
{
    Tokens = registrationTokens,
    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}");
}

বিষয়গুলিতে বার্তা প্রেরণ করুন

আপনি কোনও বিষয় তৈরি করার পরে, ক্লায়েন্টের পাশের বিষয়টিতে বা সার্ভার এপিআইয়ের মাধ্যমে ক্লায়েন্ট অ্যাপের উদাহরণগুলি সাবস্ক্রাইব করে, আপনি বিষয়টিতে বার্তা প্রেরণ করতে পারেন। যদি এটি আপনার প্রথমবারের বিল্ডিং FCM জন্য অনুরোধগুলি প্রেরণ করে তবে গুরুত্বপূর্ণ ব্যাকগ্রাউন্ড এবং সেটআপ তথ্যের জন্য আপনার সার্ভারের পরিবেশ এবং FCM গাইডটি দেখুন।

ব্যাকএন্ডে আপনার প্রেরণের যুক্তিগুলিতে, পছন্দসই বিষয়ের নামটি দেখানো হিসাবে নির্দিষ্ট করুন:

// 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);
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 -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 প্রথমে বন্ধনীগুলির কোনও শর্তকে মূল্যায়ন করে এবং তারপরে বাম থেকে ডানে অভিব্যক্তিটি মূল্যায়ন করে। উপরের অভিব্যক্তিতে, কোনও একক বিষয়ে সাবস্ক্রাইব করা ব্যবহারকারী বার্তাটি গ্রহণ করেন না। তেমনিভাবে, যে ব্যবহারকারী TopicA সাবস্ক্রাইব করেন না তিনি বার্তাটি পান না। এই সংমিশ্রণগুলি এটি গ্রহণ করে:

  • TopicA এবং TopicB
  • TopicA এবং TopicC

আপনি আপনার শর্তাধীন অভিব্যক্তিতে পাঁচটি পর্যন্ত বিষয় অন্তর্ভুক্ত করতে পারেন।

একটি শর্ত পাঠাতে:

// 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);
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 -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

ডিভাইস গ্রুপগুলিতে বার্তা প্রেরণ করুন

ডিভাইস গ্রুপগুলিতে বার্তা প্রেরণ করতে, HTTP ভি 1 এপিআই ব্যবহার করুন। আপনি যদি বর্তমানে অবনমিত উত্তরাধিকার ব্যবহার করে ডিভাইস গ্রুপগুলিতে পাঠাচ্ছেন তবে এইচটিটিপি বা এক্সএমপিপি -র জন্য এপিআই প্রেরণ করুন, বা লিগ্যাসি প্রোটোকলের উপর ভিত্তি করে নোড.জেএসের জন্য Firebase Admin SDK কোনও পুরানো সংস্করণ প্রেরণ করুন, আমরা আপনাকে দৃ strongly ়ভাবে সুপারিশ করছি যে আপনি দৃ strongly ়ভাবে সুপারিশ করুন যে আপনি দৃ strongly ়ভাবে সুপারিশ করুন যে আপনি উচ্চতম সুযোগে http ভি 1 এপিআইতে স্থানান্তরিত করুন । উত্তরাধিকার প্রেরণ এপিআইগুলি 2024 সালের জুনে অক্ষম এবং অপসারণ করা হবে।

কোনও ডিভাইস গ্রুপে বার্তা প্রেরণ পাঠানো অনুরোধগুলি অনুমোদনের জন্য একই পদ্ধতি ব্যবহার করে একটি পৃথক ডিভাইসে বার্তা প্রেরণের সাথে খুব মিল। গ্রুপ বিজ্ঞপ্তি কীতে token ক্ষেত্রটি সেট করুন:

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":{
      "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ",
      "data":{
        "hello": "This is a Firebase Cloud Messaging device group message!"
      }
   }
}
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "data":{
     "hello": "This is a Firebase Cloud Messaging device group message!"
   },
   "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

বার্তাগুলির একটি ব্যাচ প্রেরণ করুন

অ্যাডমিন এসডিকে ব্যাচে বার্তা প্রেরণ সমর্থন করে। আপনি প্রতিটি বার্তার জন্য পৃথক এইচটিটিপি অনুরোধ প্রেরণের চেয়ে উল্লেখযোগ্য পারফরম্যান্সের উন্নতি সহ একটি একক ব্যাচে 500 টি পর্যন্ত বার্তাগুলি গ্রুপ করতে পারেন এবং সেগুলি সমস্ত একক এপিআই কলটিতে প্রেরণ করতে পারেন।

এই বৈশিষ্ট্যটি বার্তাগুলির একটি কাস্টমাইজড সেট তৈরি করতে এবং বিষয়গুলি বা নির্দিষ্ট ডিভাইস রেজিস্ট্রেশন টোকেন সহ বিভিন্ন প্রাপকদের কাছে প্রেরণ করতে ব্যবহার করা যেতে পারে। এই বৈশিষ্ট্যটি ব্যবহার করুন যখন উদাহরণস্বরূপ, আপনাকে বার্তার বডিটিতে কিছুটা আলাদা বিশদ সহ বিভিন্ন শ্রোতাদের একসাথে বার্তা প্রেরণ করতে হবে।

// 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().sendAll(messages)
  .then((response) => {
    console.log(response.successCount + ' 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().sendAll(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.
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_all(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{
			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.SendAll(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)
// 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",
        },
        Token = registrationToken,
    },
    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");

সরাসরি বুট-সক্ষম করা বার্তাগুলি প্রেরণ করুন (কেবলমাত্র অ্যান্ড্রয়েড)

আপনি এইচটিটিপি ভি 1 বা লিগ্যাসি এইচটিটিপি এপিআই ব্যবহার করে সরাসরি বুট মোডে ডিভাইসে বার্তা প্রেরণ করতে পারেন। ডাইরেক্ট বুট মোডে ডিভাইসগুলিতে প্রেরণের আগে, নিশ্চিত হয়ে নিন যে আপনি ক্লায়েন্ট ডিভাইসগুলিকে সরাসরি বুট মোডে এফসিএম বার্তাগুলি গ্রহণ করতে সক্ষম করার পদক্ষেপগুলি সম্পন্ন করেছেন।

এফসিএম ভি 1 এইচটিটিপি এপিআই ব্যবহার করে প্রেরণ করুন

বার্তার অনুরোধে অবশ্যই "ডাইরেক্ট_বুট_ক" কী অন্তর্ভুক্ত থাকতে হবে: অনুরোধ বডিটির AndroidConfig বিকল্পগুলিতে "direct_boot_ok" : true । যেমন:

https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send
Content-Type:application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA

{
  "message":{
    "token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
    "data": {
      "score": "5x1",
      "time": "15:10"
    },
    "android": {
      "direct_boot_ok": true,
    },
}

প্ল্যাটফর্ম জুড়ে বার্তা কাস্টমাইজ করুন

Firebase Admin SDK এবং এফসিএম ভি 1 এইচটিটিপি প্রোটোকল উভয়ই আপনার বার্তার অনুরোধগুলিকে message অবজেক্টে উপলব্ধ সমস্ত ক্ষেত্র সেট করার অনুমতি দেয়। এর মধ্যে রয়েছে:

  • ক্ষেত্রগুলির একটি সাধারণ সেট বার্তাগুলি প্রাপ্ত সমস্ত অ্যাপ্লিকেশন দৃষ্টান্ত দ্বারা ব্যাখ্যা করা যায়।
  • AndroidConfig এবং WebpushConfig মতো ক্ষেত্রগুলির প্ল্যাটফর্ম-নির্দিষ্ট সেটগুলি কেবলমাত্র নির্দিষ্ট প্ল্যাটফর্মে চলমান অ্যাপ্লিকেশনগুলির দ্বারা ব্যাখ্যা করা হয়।

প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলি আপনাকে বিভিন্ন প্ল্যাটফর্মের জন্য বার্তাগুলি কাস্টমাইজ করার জন্য নমনীয়তা দেয় যাতে সেগুলি সঠিকভাবে পরিচালনা করা হয় তা নিশ্চিত করে। এফসিএম ব্যাকএন্ড সমস্ত নির্দিষ্ট পরামিতিগুলিকে অ্যাকাউন্টে নিয়ে যাবে এবং প্রতিটি প্ল্যাটফর্মের জন্য বার্তাটি কাস্টমাইজ করবে।

যখন সাধারণ ক্ষেত্রগুলি ব্যবহার করবেন

আপনি যখন সাধারণ ক্ষেত্রগুলি ব্যবহার করুন:

  • অ্যাপল, অ্যান্ড্রয়েড এবং ওয়েব - সমস্ত প্ল্যাটফর্মে অ্যাপ উদাহরণগুলিকে লক্ষ্য করে
  • বিষয়গুলিতে বার্তা প্রেরণ

প্ল্যাটফর্ম নির্বিশেষে সমস্ত অ্যাপ্লিকেশন উদাহরণগুলি নিম্নলিখিত সাধারণ ক্ষেত্রগুলি ব্যাখ্যা করতে পারে:

প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলি কখন ব্যবহার করবেন

আপনি চাইলে প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলি ব্যবহার করুন:

  • কেবলমাত্র নির্দিষ্ট প্ল্যাটফর্মগুলিতে ক্ষেত্রগুলি প্রেরণ করুন
  • সাধারণ ক্ষেত্রগুলি ছাড়াও প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলি প্রেরণ করুন

আপনি যখনই কেবল নির্দিষ্ট প্ল্যাটফর্মগুলিতে মানগুলি প্রেরণ করতে চান, সাধারণ ক্ষেত্রগুলি ব্যবহার করবেন না ; প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলি ব্যবহার করুন। উদাহরণস্বরূপ, কেবল অ্যাপল প্ল্যাটফর্ম এবং ওয়েবকে একটি বিজ্ঞপ্তি প্রেরণ করতে তবে অ্যান্ড্রয়েডে নয়, আপনাকে অবশ্যই দুটি পৃথক ক্ষেত্রের ক্ষেত্র ব্যবহার করতে হবে, একটি অ্যাপলের জন্য এবং একটি ওয়েবের জন্য ব্যবহার করতে হবে।

আপনি যখন নির্দিষ্ট বিতরণ বিকল্পগুলির সাথে বার্তা প্রেরণ করছেন, তখন সেগুলি সেট করতে প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলি ব্যবহার করুন। আপনি চাইলে প্ল্যাটফর্মের জন্য বিভিন্ন মান নির্দিষ্ট করতে পারেন। যাইহোক, আপনি যখন প্ল্যাটফর্মগুলিতে মূলত একই মান সেট করতে চান, আপনাকে অবশ্যই প্ল্যাটফর্ম-নির্দিষ্ট ক্ষেত্রগুলি ব্যবহার করতে হবে। এটি কারণ প্রতিটি প্ল্যাটফর্ম মানটি কিছুটা আলাদাভাবে ব্যাখ্যা করতে পারে-উদাহরণস্বরূপ, সময়-থেকে লাইভ অ্যান্ড্রয়েডে সেকেন্ডের মধ্যে মেয়াদোত্তীর্ণ সময় হিসাবে সেট করা হয়, যখন অ্যাপল-এ এটি মেয়াদোত্তীর্ণের তারিখ হিসাবে সেট করা হয়।

উদাহরণ: রঙ এবং আইকন বিকল্প সহ বিজ্ঞপ্তি বার্তা

এই উদাহরণ প্রেরণ অনুরোধটি সমস্ত প্ল্যাটফর্মগুলিতে একটি সাধারণ বিজ্ঞপ্তি শিরোনাম এবং সামগ্রী প্রেরণ করে তবে এটি অ্যান্ড্রয়েড ডিভাইসে কিছু প্ল্যাটফর্ম-নির্দিষ্ট ওভাররাইডও প্রেরণ করে।

অ্যান্ড্রয়েডের জন্য, অনুরোধটি অ্যান্ড্রয়েড ডিভাইসে প্রদর্শনের জন্য একটি বিশেষ আইকন এবং রঙ সেট করে। অ্যান্ড্রয়েডনোটিফিকেশনটির জন্য রেফারেন্সে উল্লিখিত হিসাবে, রঙটি #RRGGBB ফর্ম্যাটে নির্দিষ্ট করা হয়েছে এবং চিত্রটি অবশ্যই অ্যান্ড্রয়েড অ্যাপ্লিকেশনটিতে স্থানীয় একটি অঙ্কনযোগ্য আইকন রিসোর্স হতে হবে।

এখানে কোনও ব্যবহারকারীর ডিভাইসে ভিজ্যুয়াল এফেক্টের একটি সান্নিধ্য:

একটি কাস্টম আইকন এবং রঙ প্রদর্শন করে দুটি ডিভাইসের সহজ অঙ্কন

const topicName = 'industry-tech';

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.'
  },
  android: {
    notification: {
      icon: 'stock_ticker_update',
      color: '#7e55c3'
    }
  },
  topic: topicName,
};

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);
  });
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())
    .setAndroidConfig(AndroidConfig.builder()
        .setTtl(3600 * 1000)
        .setNotification(AndroidNotification.builder()
            .setIcon("stock_ticker_update")
            .setColor("#f45342")
            .build())
        .build())
    .setApnsConfig(ApnsConfig.builder()
        .setAps(Aps.builder()
            .setBadge(42)
            .build())
        .build())
    .setTopic("industry-tech")
    .build();
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.',
    ),
    android=messaging.AndroidConfig(
        ttl=datetime.timedelta(seconds=3600),
        priority='normal',
        notification=messaging.AndroidNotification(
            icon='stock_ticker_update',
            color='#f45342'
        ),
    ),
    apns=messaging.APNSConfig(
        payload=messaging.APNSPayload(
            aps=messaging.Aps(badge=42),
        ),
    ),
    topic='industry-tech',
)
oneHour := time.Duration(1) * time.Hour
badge := 42
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.",
	},
	Android: &messaging.AndroidConfig{
		TTL: &oneHour,
		Notification: &messaging.AndroidNotification{
			Icon:  "stock_ticker_update",
			Color: "#f45342",
		},
	},
	APNS: &messaging.APNSConfig{
		Payload: &messaging.APNSPayload{
			Aps: &messaging.Aps{
				Badge: &badge,
			},
		},
	},
	Topic: "industry-tech",
}
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.",
    },
    Android = new AndroidConfig()
    {
        TimeToLive = TimeSpan.FromHours(1),
        Notification = new AndroidNotification()
        {
            Icon = "stock_ticker_update",
            Color = "#f45342",
        },
    },
    Apns = new ApnsConfig()
    {
        Aps = new Aps()
        {
            Badge = 42,
        },
    },
    Topic = "industry-tech",
};
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":"industry-tech",
     "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."
     },
     "android":{
       "notification":{
         "icon":"stock_ticker_update",
         "color":"#7e55c3"
       }
     }
   }
 }

বার্তা বডিটিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলিতে সম্পূর্ণ বিশদ জন্য এইচটিটিপি ভি 1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: একটি কাস্টম চিত্র সহ বিজ্ঞপ্তি বার্তা

নিম্নলিখিত উদাহরণ প্রেরণ অনুরোধটি সমস্ত প্ল্যাটফর্মগুলিতে একটি সাধারণ বিজ্ঞপ্তি শিরোনাম প্রেরণ করে তবে এটি একটি চিত্রও প্রেরণ করে। এখানে কোনও ব্যবহারকারীর ডিভাইসে ভিজ্যুয়াল এফেক্টের একটি সান্নিধ্য:

একটি প্রদর্শন বিজ্ঞপ্তিতে একটি চিত্রের সহজ অঙ্কন

Node.js বিশ্রাম
const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Sparky says hello!'
  },
  android: {
    notification: {
      imageUrl: 'https://foo.bar.pizza-monster.png'
    }
  },
  apns: {
    payload: {
      aps: {
        'mutable-content': 1
      }
    },
    fcm_options: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  webpush: {
    headers: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  topic: topicName,
};

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);
  });
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":"industry-tech",
     "notification":{
       "title":"Sparky says hello!",
     },
     "android":{
       "notification":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "mutable-content":1
         }
       },
       "fcm_options": {
           "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "webpush":{
       "headers":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     }
   }
 }

বার্তা বডিটিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলিতে সম্পূর্ণ বিশদ জন্য এইচটিটিপি ভি 1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: সম্পর্কিত ক্লিক ক্রিয়া সহ বিজ্ঞপ্তি বার্তা

নিম্নলিখিত উদাহরণ প্রেরণ অনুরোধটি সমস্ত প্ল্যাটফর্মগুলিতে একটি সাধারণ বিজ্ঞপ্তি শিরোনাম প্রেরণ করে, তবে এটি অ্যাপটিকে বিজ্ঞপ্তির সাথে ইন্টারঅ্যাক্ট করার প্রতিক্রিয়া হিসাবে সম্পাদন করার জন্য একটি ক্রিয়াও প্রেরণ করে। এখানে কোনও ব্যবহারকারীর ডিভাইসে ভিজ্যুয়াল এফেক্টের একটি সান্নিধ্য:

কোনও ব্যবহারকারীর ট্যাপের সহজ অঙ্কন একটি ওয়েব পৃষ্ঠা খোলার

Node.js বিশ্রাম
const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Breaking News....'
  },
  android: {
    notification: {
      clickAction: 'news_intent'
    }
  },
  apns: {
    payload: {
      aps: {
        'category': 'INVITE_CATEGORY'
      }
    }
  },
  webpush: {
    fcmOptions: {
      link: 'breakingnews.html'
    }
  },
  topic: topicName,
};

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);
  });
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":"industry-tech",
     "notification":{
       "title":"Breaking News...",
     },
     "android":{
       "notification":{
         "click_action":"news_intent"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "category" : "INVITE_CATEGORY"
         }
       },
     },
     "webpush":{
       "fcm_options":{
         "link":"breakingnews.html"
       }
     }
   }
 }

বার্তা বডিটিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলিতে সম্পূর্ণ বিশদ জন্য এইচটিটিপি ভি 1 রেফারেন্স ডকুমেন্টেশন দেখুন।

উদাহরণ: স্থানীয়করণ বিকল্পগুলির সাথে বিজ্ঞপ্তি বার্তা

নিম্নলিখিত উদাহরণ প্রেরণ অনুরোধ ক্লায়েন্টের স্থানীয় বার্তা প্রদর্শন করার জন্য স্থানীয়করণ বিকল্পগুলি প্রেরণ করে। এখানে কোনও ব্যবহারকারীর ডিভাইসে ভিজ্যুয়াল এফেক্টের একটি সান্নিধ্য:

দুটি ডিভাইসের সহজ অঙ্কন ইংরেজি এবং স্প্যানিশ ভাষায় পাঠ্য প্রদর্শন করে

Node.js বিশ্রাম
var topicName = 'industry-tech';

var message = {
  android: {
    ttl: 3600000,
    notification: {
      bodyLocKey: 'STOCK_NOTIFICATION_BODY',
      bodyLocArgs: ['FooCorp', '11.80', '835.67', '1.43']
    }
  },
  apns: {
    payload: {
      aps: {
        alert: {
          locKey: 'STOCK_NOTIFICATION_BODY',
          locArgs: ['FooCorp', '11.80', '835.67', '1.43']
        }
      }
    }
  },
  topic: topicName,
};

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);
  });
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":"Tech",
             "android":{
               "ttl":"3600s",
               "notification":{
                 "body_loc_key": "STOCK_NOTIFICATION_BODY",
                 "body_loc_args":  ["FooCorp", "11.80", "835.67", "1.43"],
               },
             },
             "apns":{
               "payload":{
                 "aps":{
                   "alert" : {
                     "loc-key": "STOCK_NOTIFICATION_BODY",
                     "loc-args":  ["FooCorp", "11.80", "835.67", "1.43"],
                    },
                 },
               },
             },
  },
}'

বার্তা বডিটিতে প্ল্যাটফর্ম-নির্দিষ্ট ব্লকগুলিতে উপলব্ধ কীগুলিতে সম্পূর্ণ বিশদ জন্য এইচটিটিপি ভি 1 রেফারেন্স ডকুমেন্টেশন দেখুন।

এইচটিটিপি ভি 1 এপিআইয়ের জন্য বিশ্রাম ত্রুটি কোডগুলি

এইচটিটিপি ভি 1 এপিআইয়ের জন্য এইচটিটিপি ত্রুটি প্রতিক্রিয়াগুলিতে একটি ত্রুটি কোড, একটি ত্রুটি বার্তা এবং ত্রুটির স্থিতি রয়েছে। এগুলিতে ত্রুটির বিষয়ে আরও বিশদ সহ details অ্যারেও থাকতে পারে।

এখানে দুটি নমুনা ত্রুটি প্রতিক্রিয়া রয়েছে:

উদাহরণ 1: একটি ডেটা বার্তায় একটি অবৈধ মান সহ এইচটিটিপি ভি 1 এপিআই অনুরোধ থেকে ত্রুটি প্রতিক্রিয়া

{
  "error": {
    "code": 400,
    "message": "Invalid value at 'message.data[0].value' (TYPE_STRING), 12",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "message.data[0].value",
            "description": "Invalid value at 'message.data[0].value' (TYPE_STRING), 12"
          }
        ]
      }
    ]
  }
}

উদাহরণ 2: একটি অবৈধ নিবন্ধকরণ টোকেন সহ এইচটিটিপি ভি 1 এপিআই অনুরোধ থেকে ত্রুটি প্রতিক্রিয়া

{
  "error": {
    "code": 400,
    "message": "The registration token is not a valid FCM registration token",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "INVALID_ARGUMENT"
      }
    ]
   }
}

নোট করুন যে উভয় বার্তাগুলির একই কোড এবং স্থিতি রয়েছে তবে বিশদ অ্যারেতে বিভিন্ন ধরণের মান রয়েছে। প্রথম উদাহরণটিতে টাইপ টাইপ রয়েছে type.googleapis.com/google.rpc.BadRequest অনুরোধ মানগুলিতে একটি ত্রুটি নির্দেশ করে। type.googleapis.com/google.firebase.fcm.v1.FcmError সাথে দ্বিতীয় উদাহরণ। অনেক ত্রুটির জন্য, বিশদ অ্যারেতে আপনাকে ডিবাগ করতে এবং একটি রেজোলিউশন খুঁজে পেতে হবে এমন তথ্য রয়েছে।

নিম্নলিখিত টেবিলটি এফসিএম ভি 1 আরইএসটি এপিআই ত্রুটি কোড এবং তাদের বিবরণ তালিকাভুক্ত করে।

ত্রুটি কোড বর্ণনা এবং রেজোলিউশন পদক্ষেপ
UNSPECIFIED_ERROR এই ত্রুটি সম্পর্কে আর কোনও তথ্য উপলব্ধ নেই। কোনোটিই নয়।
INVALID_ARGUMENT (এইচটিটিপি ত্রুটি কোড = 400) অনুরোধ পরামিতিগুলি অবৈধ ছিল। কোন ক্ষেত্রটি অবৈধ ছিল তা নির্দিষ্ট করতে google.rpc.BadRequest সম্ভাব্য কারণগুলির মধ্যে অবৈধ নিবন্ধকরণ, অবৈধ প্যাকেজের নাম, বার্তা খুব বড়, অবৈধ ডেটা কী, অবৈধ টিটিএল বা অন্যান্য অবৈধ পরামিতি অন্তর্ভুক্ত রয়েছে।
অবৈধ নিবন্ধকরণ : আপনি সার্ভারে পাস করা রেজিস্ট্রেশন টোকেনের ফর্ম্যাটটি পরীক্ষা করুন। নিশ্চিত হয়ে নিন যে এটি ক্লায়েন্ট অ্যাপ্লিকেশনটি এফসিএম -এর সাথে নিবন্ধকরণ থেকে প্রাপ্ত রেজিস্ট্রেশন টোকেনের সাথে মেলে। টোকেন কাটা বা অতিরিক্ত অক্ষর যুক্ত করবেন না।
অবৈধ প্যাকেজের নাম : নিশ্চিত হয়ে নিন যে বার্তাটি একটি নিবন্ধকরণ টোকেনের সাথে সম্বোধন করা হয়েছে যার প্যাকেজের নামটি অনুরোধে পাস করা মানের সাথে মেলে।
বার্তা খুব বড় : পরীক্ষা করুন যে কোনও বার্তায় অন্তর্ভুক্ত পে -লোড ডেটার মোট আকার এফসিএম সীমা ছাড়িয়ে যায় না: বেশিরভাগ বার্তার জন্য 4096 বাইট বা বিষয়গুলিতে বার্তাগুলির ক্ষেত্রে 2048 বাইট। এর মধ্যে কী এবং মান উভয়ই অন্তর্ভুক্ত রয়েছে।
অবৈধ ডেটা কী : পে -লোড ডেটাতে কোনও কী নেই (যেমন থেকে, বা জিসিএম, বা গুগল দ্বারা উপসর্গযুক্ত কোনও মান) যা এফসিএম দ্বারা অভ্যন্তরীণভাবে ব্যবহৃত হয়। নোট করুন যে কিছু শব্দ (যেমন ধসফেস_কি) এফসিএম দ্বারাও ব্যবহৃত হয় তবে পে -লোডে অনুমোদিত হয়, সেক্ষেত্রে পে -লোড মানটি এফসিএম মান দ্বারা ওভাররাইড করা হবে।
অবৈধ টিটিএল : টিটিএলে ব্যবহৃত মানটি একটি পূর্ণসংখ্যা যা 0 থেকে 2,419,200 (4 সপ্তাহ) এর মধ্যে সেকেন্ডে সময়কাল উপস্থাপন করে।
অবৈধ পরামিতি : প্রদত্ত পরামিতিগুলির সঠিক নাম এবং প্রকার রয়েছে কিনা তা পরীক্ষা করে দেখুন।
UNREGISTERED (এইচটিটিপি ত্রুটি কোড = 404) অ্যাপ্লিকেশন উদাহরণটি এফসিএম থেকে নিবন্ধভুক্ত ছিল। এর সাধারণত অর্থ হ'ল ব্যবহৃত টোকেনটি আর বৈধ নয় এবং একটি নতুন ব্যবহার করতে হবে। এই ত্রুটিটি রেজিস্ট্রেশন টোকেন বা নিবন্ধভুক্ত টোকেনগুলি অনুপস্থিত কারণে হতে পারে।
অনুপস্থিত নিবন্ধকরণ : যদি বার্তার লক্ষ্যটি একটি token মান হয় তবে অনুরোধটিতে একটি নিবন্ধকরণ টোকেন রয়েছে তা পরীক্ষা করুন।
নিবন্ধিত নয় : একটি বিদ্যমান রেজিস্ট্রেশন টোকেন বেশ কয়েকটি পরিস্থিতিতে বৈধ হতে বন্ধ করতে পারে, সহ:
- যদি ক্লায়েন্ট অ্যাপটি এফসিএম দিয়ে নিবন্ধভুক্ত করে।
- যদি ক্লায়েন্ট অ্যাপ্লিকেশনটি স্বয়ংক্রিয়ভাবে নিবন্ধভুক্ত হয়, যা ব্যবহারকারী যদি অ্যাপ্লিকেশনটি আনইনস্টল করে তবে ঘটতে পারে। উদাহরণস্বরূপ, আইওএস -এ, যদি এপিএনএস প্রতিক্রিয়া পরিষেবা এপিএনএস টোকেনটিকে অবৈধ হিসাবে রিপোর্ট করে।
- যদি নিবন্ধকরণ টোকেনের মেয়াদ শেষ হয় (উদাহরণস্বরূপ, গুগল রেজিস্ট্রেশন টোকেনগুলি রিফ্রেশ করার সিদ্ধান্ত নিতে পারে, বা আইওএস ডিভাইসের জন্য এপিএনএস টোকেনটির মেয়াদ শেষ হয়ে গেছে)।
- যদি ক্লায়েন্ট অ্যাপটি আপডেট করা হয় তবে নতুন সংস্করণটি বার্তা পাওয়ার জন্য কনফিগার করা হয় না।
এই সমস্ত ক্ষেত্রে, অ্যাপ্লিকেশন সার্ভার থেকে এই নিবন্ধকরণ টোকেনটি সরান এবং বার্তাগুলি প্রেরণে এটি ব্যবহার বন্ধ করুন।
SENDER_ID_MISMATCH (এইচটিটিপি ত্রুটি কোড = 403) অনুমোদিত প্রেরক আইডি নিবন্ধকরণ টোকেনের জন্য প্রেরক আইডি থেকে পৃথক। একটি রেজিস্ট্রেশন টোকেন প্রেরকের একটি নির্দিষ্ট গ্রুপের সাথে আবদ্ধ। যখন কোনও ক্লায়েন্ট অ্যাপ এফসিএমের জন্য নিবন্ধভুক্ত করে, এটি অবশ্যই নির্দিষ্ট করতে হবে যে কোন প্রেরকদের বার্তা প্রেরণের অনুমতি দেওয়া হয়েছে। ক্লায়েন্ট অ্যাপে বার্তা প্রেরণ করার সময় আপনার সেই প্রেরক আইডিগুলির মধ্যে একটি ব্যবহার করা উচিত। আপনি যদি অন্য কোনও প্রেরকের কাছে স্যুইচ করেন তবে বিদ্যমান রেজিস্ট্রেশন টোকেনগুলি কাজ করবে না।
QUOTA_EXCEEDED (এইচটিটিপি ত্রুটি কোড = 429) বার্তা লক্ষ্যমাত্রার জন্য প্রেরণ সীমা ছাড়িয়ে গেছে। কোন কোটা ছাড়িয়ে গেছে তা নির্দিষ্ট করতে google.rpc.QuotaFailure টাইপের একটি এক্সটেনশন ফিরে আসে। এই ত্রুটিটি অতিক্রম করা বার্তা রেট কোটা, ছাড়িয়ে যাওয়া ডিভাইস বার্তা রেট কোটা বা টপিক মেসেজ রেট কোটা ছাড়িয়ে যেতে পারে।
বার্তার হার ছাড়িয়ে গেছে : বার্তা প্রেরণের হার খুব বেশি। আপনি অবশ্যই বার্তা প্রেরণ করতে হবে সামগ্রিক হার হ্রাস করতে হবে। প্রত্যাখ্যানিত বার্তাগুলি পুনরায় চেষ্টা করতে ন্যূনতম প্রাথমিক বিলম্বের সাথে এক্সফোনেনশিয়াল ব্যাকঅফ ব্যবহার করুন।
ডিভাইস বার্তার হার ছাড়িয়ে গেছে : একটি নির্দিষ্ট ডিভাইসে বার্তাগুলির হার খুব বেশি। একটি একক ডিভাইসে বার্তা রেট সীমা দেখুন । এই ডিভাইসে প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং পুনরায় চেষ্টা করার জন্য সূচকীয় ব্যাকঅফ ব্যবহার করুন।
বিষয় বার্তার হার ছাড়িয়ে গেছে : কোনও নির্দিষ্ট বিষয়ের গ্রাহকদের কাছে বার্তাগুলির হার খুব বেশি। এই বিষয়ের জন্য প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং পুনরায় চেষ্টা করার জন্য ন্যূনতম প্রাথমিক বিলম্বের সাথে এক্সফোনেনশিয়াল ব্যাকঅফ ব্যবহার করুন।
UNAVAILABLE (এইচটিটিপি ত্রুটি কোড = 503) সার্ভারটি ওভারলোড হয়েছে। সার্ভার সময়মতো অনুরোধটি প্রক্রিয়া করতে পারেনি। একই অনুরোধটি আবার চেষ্টা করুন, তবে আপনাকে অবশ্যই:
- যদি এফসিএম সংযোগ সার্ভারের প্রতিক্রিয়াতে অন্তর্ভুক্ত থাকে তবে পুনরায় চেষ্টা-গ্রহণের শিরোনামকে সম্মান করুন।
- আপনার পুনরায় চেষ্টা পদ্ধতিতে ক্ষতিকারক ব্যাকঅফ প্রয়োগ করুন। (যেমন আপনি যদি প্রথম পুনরায় চেষ্টা করার আগে এক সেকেন্ড অপেক্ষা করেন তবে পরেরটির আগে কমপক্ষে দুই সেকেন্ড অপেক্ষা করুন, তারপরে 4 সেকেন্ড এবং আরও কিছু)। আপনি যদি একাধিক বার্তা প্রেরণ করছেন তবে জিটারিং প্রয়োগ করার বিষয়টি বিবেচনা করুন। আরও তথ্যের জন্য, হ্যান্ডলিং রিট্রিগুলি দেখুন , বা এফসিএমকে প্রভাবিত করে এমন কোনও চলমান পরিষেবা বাধা রয়েছে কিনা তা সনাক্ত করতে এফসিএম স্ট্যাটাস ড্যাশবোর্ডটি পরীক্ষা করুন। প্রেরকরা যে সমস্যাগুলি অস্বচ্ছল হওয়ার ঝুঁকি নিয়ে আসে।
INTERNAL (এইচটিটিপি ত্রুটি কোড = 500) একটি অজানা অভ্যন্তরীণ ত্রুটি ঘটেছে। অনুরোধটি প্রক্রিয়া করার চেষ্টা করার সময় সার্ভারটি একটি ত্রুটির মুখোমুখি হয়েছিল। আপনি পুনরুদ্ধার পরিচালনা করতে বা এফসিএম স্ট্যাটাস ড্যাশবোর্ড পরীক্ষা করার পরামর্শের পরে একই অনুরোধটি পুনরায় চেষ্টা করতে পারেন। এফসিএমকে প্রভাবিত করে এমন কোনও চলমান পরিষেবা বাধা রয়েছে কিনা তা সনাক্ত করতে। যদি ত্রুটিটি অব্যাহত থাকে তবে দয়া করে ফায়ারবেস সমর্থনের সাথে যোগাযোগ করুন।
THIRD_PARTY_AUTH_ERROR (এইচটিটিপি ত্রুটি কোড = 401) এপিএনএস শংসাপত্র বা ওয়েব পুশ এথ কীটি অবৈধ বা অনুপস্থিত ছিল। আইওএস ডিভাইস বা একটি ওয়েব পুশ নিবন্ধকরণকে লক্ষ্যযুক্ত একটি বার্তা প্রেরণ করা যায়নি। আপনার বিকাশ এবং উত্পাদন শংসাপত্রগুলির বৈধতা পরীক্ষা করুন।

অ্যাডমিন ত্রুটি কোড

নিম্নলিখিত টেবিলটি ফায়ারবেস অ্যাডমিন FCM এপিআই ত্রুটি কোডগুলি এবং তাদের বিবরণগুলি প্রস্তাবিত রেজোলিউশন পদক্ষেপগুলি সহ তালিকাভুক্ত করে।

ত্রুটি কোড বর্ণনা এবং রেজোলিউশন পদক্ষেপ
messaging/invalid-argument একটি FCM পদ্ধতিতে একটি অবৈধ যুক্তি সরবরাহ করা হয়েছিল। ত্রুটি বার্তায় অতিরিক্ত তথ্য থাকা উচিত।
messaging/invalid-recipient উদ্দেশ্যযুক্ত বার্তা প্রাপক অবৈধ। ত্রুটি বার্তায় অতিরিক্ত তথ্য থাকা উচিত।
messaging/invalid-payload একটি অবৈধ বার্তা পে -লোড অবজেক্ট সরবরাহ করা হয়েছিল। ত্রুটি বার্তায় অতিরিক্ত তথ্য থাকা উচিত।
messaging/invalid-data-payload-key ডেটা বার্তা পে -লোডে একটি অবৈধ কী রয়েছে। সীমাবদ্ধ কীগুলির জন্য DataMessagePayload জন্য রেফারেন্স ডকুমেন্টেশন দেখুন।
messaging/payload-size-limit-exceeded প্রদত্ত বার্তা পে -লোড FCM আকারের সীমা ছাড়িয়ে গেছে। সীমাটি বেশিরভাগ বার্তাগুলির জন্য 4096 বাইট। বিষয়গুলিতে প্রেরিত বার্তাগুলির জন্য, সীমাটি 2048 বাইট। মোট পে -লোড আকারে কী এবং মান উভয়ই অন্তর্ভুক্ত।
messaging/invalid-options একটি অবৈধ বার্তা বিকল্প অবজেক্ট সরবরাহ করা হয়েছিল। ত্রুটি বার্তায় অতিরিক্ত তথ্য থাকা উচিত।
messaging/invalid-registration-token অবৈধ নিবন্ধকরণ টোকেন সরবরাহ করা হয়েছে। নিশ্চিত হয়ে নিন যে এটি ক্লায়েন্ট অ্যাপ্লিকেশনটি FCM সাথে নিবন্ধকরণ থেকে প্রাপ্ত রেজিস্ট্রেশন টোকেনের সাথে মেলে। এতে অতিরিক্ত অক্ষর কাটা বা যুক্ত করবেন না।
messaging/registration-token-not-registered প্রদত্ত রেজিস্ট্রেশন টোকেন নিবন্ধিত নয়। পূর্বে বৈধ রেজিস্ট্রেশন টোকেন বিভিন্ন কারণে নিবন্ধভুক্ত করা যেতে পারে, সহ:
  • ক্লায়েন্ট অ্যাপটি FCM থেকে নিজেকে নিবন্ধভুক্ত করেছে।
  • ক্লায়েন্ট অ্যাপ্লিকেশনটি স্বয়ংক্রিয়ভাবে নিবন্ধভুক্ত ছিল। যদি ব্যবহারকারী অ্যাপ্লিকেশনটি আনইনস্টল করে বা অ্যাপল প্ল্যাটফর্মগুলিতে, যদি এপিএনএস প্রতিক্রিয়া পরিষেবাটি এপিএনএস টোকেনটিকে অবৈধ হিসাবে রিপোর্ট করে।
  • রেজিস্ট্রেশন টোকেনের মেয়াদ শেষ হয়ে গেছে। উদাহরণস্বরূপ, গুগল নিবন্ধকরণ টোকেনগুলি রিফ্রেশ করার সিদ্ধান্ত নিতে পারে বা অ্যাপএনএস টোকেন অ্যাপল ডিভাইসগুলির জন্য মেয়াদোত্তীর্ণ হতে পারে।
  • ক্লায়েন্ট অ্যাপটি আপডেট করা হয়েছিল, তবে নতুন সংস্করণটি বার্তাগুলি পাওয়ার জন্য কনফিগার করা হয়নি।
এই সমস্ত ক্ষেত্রে, এই নিবন্ধকরণ টোকেন সরান এবং বার্তা প্রেরণের জন্য এটি ব্যবহার বন্ধ করুন।
messaging/invalid-package-name বার্তাটি একটি নিবন্ধকরণ টোকেনকে সম্বোধন করা হয়েছিল যার প্যাকেজের নাম সরবরাহিত restrictedPackageName বিকল্পের সাথে মেলে না।
messaging/message-rate-exceeded একটি নির্দিষ্ট লক্ষ্যে বার্তাগুলির হার খুব বেশি। এই ডিভাইস বা বিষয়টিতে প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং তাত্ক্ষণিকভাবে এই লক্ষ্যটিতে প্রেরণ পুনরায় চেষ্টা করবেন না।
messaging/device-message-rate-exceeded একটি নির্দিষ্ট ডিভাইসে বার্তাগুলির হার খুব বেশি। এই ডিভাইসে প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং তাত্ক্ষণিকভাবে এই ডিভাইসে প্রেরণ পুনরায় চেষ্টা করবেন না।
messaging/topics-message-rate-exceeded কোনও নির্দিষ্ট বিষয়ের গ্রাহকদের কাছে বার্তাগুলির হার খুব বেশি। এই বিষয়টির জন্য প্রেরিত বার্তাগুলির সংখ্যা হ্রাস করুন এবং তাত্ক্ষণিকভাবে এই বিষয়টিতে প্রেরণ পুনরায় চেষ্টা করবেন না।
messaging/too-many-topics একটি রেজিস্ট্রেশন টোকেন সর্বাধিক সংখ্যক বিষয়ের সাবস্ক্রাইব করা হয়েছে এবং আর কোনও সাবস্ক্রাইব করা যাবে না।
messaging/invalid-apns-credentials কোনও অ্যাপল ডিভাইসে লক্ষ্যযুক্ত একটি বার্তা প্রেরণ করা যায়নি কারণ প্রয়োজনীয় এপিএনএস এসএসএল শংসাপত্রটি আপলোড করা হয়নি বা মেয়াদ শেষ হয়ে গেছে। আপনার বিকাশ এবং উত্পাদন শংসাপত্রগুলির বৈধতা পরীক্ষা করুন।
messaging/mismatched-credential এই এসডিকে প্রমাণীকরণের জন্য ব্যবহৃত শংসাপত্রের সরবরাহিত নিবন্ধকরণ টোকেনের সাথে সম্পর্কিত ডিভাইসে বার্তা প্রেরণের অনুমতি নেই। নিশ্চিত করুন যে শংসাপত্র এবং নিবন্ধকরণ টোকেন উভয়ই একই ফায়ারবেস প্রকল্পের অন্তর্গত। কীভাবে Firebase Admin SDK এসকে প্রমাণীকরণ করবেন সে সম্পর্কে ডকুমেন্টেশনের জন্য আপনার অ্যাপ্লিকেশনটিতে ফায়ারবেস যুক্ত করুন
messaging/authentication-error এসডিকে FCM সার্ভারগুলিতে প্রমাণীকরণ করতে পারেনি। নিশ্চিত হয়ে নিন যে আপনি Firebase Admin SDK একটি শংসাপত্রের সাথে প্রমাণীকরণ করেছেন যা FCM বার্তা প্রেরণের উপযুক্ত অনুমতি রয়েছে। কীভাবে Firebase Admin SDK এসকে প্রমাণীকরণ করবেন সে সম্পর্কে ডকুমেন্টেশনের জন্য আপনার অ্যাপ্লিকেশনটিতে ফায়ারবেস যুক্ত করুন
messaging/server-unavailable FCM সার্ভার সময়মতো অনুরোধটি প্রক্রিয়া করতে পারেনি। আপনার একই অনুরোধটি আবার চেষ্টা করা উচিত, তবে আপনাকে অবশ্যই:
  • যদি এটি FCM সংযোগ সার্ভারের প্রতিক্রিয়াতে অন্তর্ভুক্ত থাকে তবে Retry-After শিরোনামকে সম্মান করুন।
  • আপনার পুনরায় চেষ্টা পদ্ধতিতে তাত্পর্যপূর্ণ ব্যাক-অফ প্রয়োগ করুন। উদাহরণস্বরূপ, আপনি যদি প্রথম পুনরায় চেষ্টা করার আগে এক সেকেন্ড অপেক্ষা করেন তবে পরেরটির আগে কমপক্ষে দুই সেকেন্ড অপেক্ষা করুন, তারপরে চার সেকেন্ড এবং আরও অনেক কিছু। আপনি যদি একাধিক বার্তা প্রেরণ করছেন, একই সাথে সমস্ত বার্তাগুলির জন্য নতুন অনুরোধ জারি করা এড়াতে অতিরিক্ত এলোমেলো পরিমাণে প্রত্যেককে স্বাধীনভাবে বিলম্ব করুন।
প্রেরকরা যে সমস্যাগুলি কালো তালিকাভুক্ত হওয়ার ঝুঁকি নিয়ে আসে।
messaging/internal-error অনুরোধটি প্রক্রিয়া করার চেষ্টা করার সময় FCM সার্ভার একটি ত্রুটির মুখোমুখি হয়েছিল। আপনি উপরের messaging/server-unavailable সারিতে তালিকাভুক্ত প্রয়োজনীয়তা অনুসরণ করে একই অনুরোধটি আবার চেষ্টা করতে পারেন। যদি ত্রুটিটি অব্যাহত থাকে তবে দয়া করে আমাদের বাগ রিপোর্ট সমর্থন চ্যানেলে সমস্যাটি রিপোর্ট করুন।
messaging/unknown-error একটি অজানা সার্ভার ত্রুটি ফিরে এসেছিল। আরও তথ্যের জন্য ত্রুটি বার্তায় কাঁচা সার্ভারের প্রতিক্রিয়া দেখুন। আপনি যদি এই ত্রুটিটি পান তবে দয়া করে আমাদের বাগ রিপোর্ট সমর্থন চ্যানেলে সম্পূর্ণ ত্রুটি বার্তাটি রিপোর্ট করুন।
,

Firebase Admin SDK বা FCM অ্যাপ্লিকেশন সার্ভার প্রোটোকলগুলি ব্যবহার করে আপনি বার্তা অনুরোধগুলি তৈরি করতে পারেন এবং এগুলি এই ধরণের লক্ষ্যগুলিতে প্রেরণ করতে পারেন:

  • বিষয়ের নাম
  • অবস্থা
  • ডিভাইস নিবন্ধকরণ টোকেন
  • ডিভাইস গ্রুপের নাম (কেবল প্রোটোকল)

আপনি পূর্বনির্ধারিত ক্ষেত্রগুলি, আপনার নিজের ব্যবহারকারী-সংজ্ঞায়িত ক্ষেত্রগুলির ডেটা পেডলোড বা উভয় ধরণের পে-লোডযুক্ত একটি বার্তা সহ বার্তা পাঠাতে পারেন। আরও তথ্যের জন্য বার্তার ধরণগুলি দেখুন।

Examples in this page show how to send notification messages using the Firebase Admin SDK (which has support for Node , Java , Python , C# , and Go ) and the v1 HTTP protocol .

Send messages to specific devices

To send to a single, specific device, pass the device's registration token as shown. See the client setup information for your platform to learn more about registration tokens.

// 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);
  });
// 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().send(message);
// Response is a message ID string.
System.out.println("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)
// 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)
// 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" },
    },
    Token = registrationToken,
};

// 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);
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":{
      "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
      "notification":{
        "body":"This is an FCM notification message!",
        "title":"FCM Message"
      }
   }
}

cURL command:

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "notification":{
     "title":"FCM Message",
     "body":"This is an FCM Message"
   },
   "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

On success, each send method returns a message ID. The Firebase Admin SDK returns the ID string in the format projects/{project_id}/messages/{message_id} . The HTTP protocol response is a single JSON key:

    {
      "name":"projects/myproject-b5ae1/messages/0:1500415314455276%31bd1c9631bd1c96"
    }

Send messages to multiple devices

The Admin FCM APIs allow you to multicast a message to a list of device registration tokens. You can specify up to 500 device registration tokens per invocation.

// Create a list containing up to 500 registration tokens.
// 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().sendMulticast(message)
  .then((response) => {
    console.log(response.successCount + ' messages were sent successfully');
  });
// Create a list containing up to 500 registration tokens.
// 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().sendMulticast(message);
// 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 registration tokens.
# 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_multicast(message)
# 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 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.SendMulticast(context.Background(), message)
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 registration tokens.
// 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()
{
    Tokens = registrationTokens,
    Data = new Dictionary<string, string>()
    {
        { "score", "850" },
        { "time", "2:45" },
    },
};

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

The return value is a list of tokens that corresponds to the order of the input tokens. This is useful when you want to check which tokens resulted in errors.

// 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().sendMulticast(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);
    }
  });
// 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().sendMulticast(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);
}
# 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_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('List of tokens that caused failures: {0}'.format(failed_tokens))
// 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.SendMulticast(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)
}
// 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()
{
    Tokens = registrationTokens,
    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}");
}

Send messages to topics

After you have created a topic, either by subscribing client app instances to the topic on the client side or via the server API , you can send messages to the topic. If this is your first time building send requests for FCM , see the guide to your server environment and FCM for important background and setup information.

In your sending logic on the backend, specify the desired topic name as shown:

// 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);
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 command:

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

To send a message to a combination of topics, specify a condition , which is a boolean expression that specifies the target topics. For example, the following condition will send messages to devices that are subscribed to TopicA and either TopicB or TopicC :

"'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"

FCM first evaluates any conditions in parentheses, and then evaluates the expression from left to right. In the above expression, a user subscribed to any single topic does not receive the message. Likewise, a user who does not subscribe to TopicA does not receive the message. These combinations do receive it:

  • TopicA and TopicB
  • TopicA and TopicC

You can include up to five topics in your conditional expression.

To send to a condition:

// 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);
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 command:

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

Send messages to device groups

To send messages to device groups, use the HTTP v1 API. If you are currently sending to device groups using the deprecated legacy send APIs for HTTP or XMPP, or any of the older versions of the Firebase Admin SDK for Node.js based on the legacy protocols, we strongly recommend that you migrate to the HTTP v1 API at the earliest opportunity. The legacy send APIs will be disabled and removed in June 2024.

Sending messages to a device group is very similar to sending messages to an individual device, using the same method to authorize send requests . Set the token field to the group notification key:

বিশ্রাম cURL command
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":{
      "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ",
      "data":{
        "hello": "This is a Firebase Cloud Messaging device group message!"
      }
   }
}
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "data":{
     "hello": "This is a Firebase Cloud Messaging device group message!"
   },
   "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

Send a batch of messages

The Admin SDKs support sending messages in batches. You can group up to 500 messages into a single batch and send them all in a single API call, with significant performance improvement over sending separate HTTP requests for each message.

This feature can be used to build a customized set of messages and send them to different recipients, including topics or specific device registration tokens. Use this feature when, for example, you need to simultaneously send messages to different audiences with slightly different details in the message body.

// 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().sendAll(messages)
  .then((response) => {
    console.log(response.successCount + ' 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().sendAll(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.
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_all(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{
			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.SendAll(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)
// 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",
        },
        Token = registrationToken,
    },
    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");

Send direct boot-enabled messages (Android only)

You can send messages to devices in direct boot mode using the HTTP v1 or legacy HTTP APIs. Before sending to devices in direct boot mode, make sure you have completed the steps to enable client devices to receive FCM messages in direct boot mode .

Send using the FCM v1 HTTP API

The message request must include the key "direct_boot_ok" : true in the AndroidConfig options of the request body. যেমন:

https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send
Content-Type:application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA

{
  "message":{
    "token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
    "data": {
      "score": "5x1",
      "time": "15:10"
    },
    "android": {
      "direct_boot_ok": true,
    },
}

Customize messages across platforms

The Firebase Admin SDK and the FCM v1 HTTP protocol both allow your message requests to set all fields available in the message object. এর মধ্যে রয়েছে:

  • a common set of fields to be interpreted by all app instances that receive the message.
  • platform-specific sets of fields, such as AndroidConfig and WebpushConfig , interpreted only by app instances running on the specified platform.

Platform-specific blocks give you flexibility to customize messages for different platforms to ensure that they are handled correctly when received. The FCM backend will take all specified parameters into account and customize the message for each platform.

When to use common fields

Use common fields when you're:

  • Targeting app instances on all platforms — Apple, Android, and web
  • Sending messages to topics

All app instances, regardless of platform, can interpret the following common fields:

When to use platform-specific fields

Use platform-specific fields when you want to:

  • Send fields only to particular platforms
  • Send platform-specific fields in addition to the common fields

Whenever you want to send values only to particular platforms, don't use common fields; use platform-specific fields. For example, to send a notification only to Apple platforms and web but not to Android, you must use two separate sets of fields, one for Apple and one for web.

When you are sending messages with specific delivery options , use platform-specific fields to set them. You can specify different values per platform if you want. However, even when you want to set essentially the same value across platforms, you must use platform-specific fields. This is because each platform may interpret the value slightly differently—for example, time-to-live is set on Android as an expiration time in seconds, while on Apple it is set as an expiration date .

Example: notification message with color and icon options

This example send request sends a common notification title and content to all platforms, but it also sends some platform-specific overrides to Android devices.

For Android, the request sets a special icon and color to display on Android devices. As noted in the reference for AndroidNotification , the color is specified in #rrggbb format, and the image must be a drawable icon resource local to the Android app.

Here's an approximation of the visual effect on a user's device:

Simple drawing of two devices, with one displaying a custom icon and color

const topicName = 'industry-tech';

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.'
  },
  android: {
    notification: {
      icon: 'stock_ticker_update',
      color: '#7e55c3'
    }
  },
  topic: topicName,
};

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);
  });
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())
    .setAndroidConfig(AndroidConfig.builder()
        .setTtl(3600 * 1000)
        .setNotification(AndroidNotification.builder()
            .setIcon("stock_ticker_update")
            .setColor("#f45342")
            .build())
        .build())
    .setApnsConfig(ApnsConfig.builder()
        .setAps(Aps.builder()
            .setBadge(42)
            .build())
        .build())
    .setTopic("industry-tech")
    .build();
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.',
    ),
    android=messaging.AndroidConfig(
        ttl=datetime.timedelta(seconds=3600),
        priority='normal',
        notification=messaging.AndroidNotification(
            icon='stock_ticker_update',
            color='#f45342'
        ),
    ),
    apns=messaging.APNSConfig(
        payload=messaging.APNSPayload(
            aps=messaging.Aps(badge=42),
        ),
    ),
    topic='industry-tech',
)
oneHour := time.Duration(1) * time.Hour
badge := 42
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.",
	},
	Android: &messaging.AndroidConfig{
		TTL: &oneHour,
		Notification: &messaging.AndroidNotification{
			Icon:  "stock_ticker_update",
			Color: "#f45342",
		},
	},
	APNS: &messaging.APNSConfig{
		Payload: &messaging.APNSPayload{
			Aps: &messaging.Aps{
				Badge: &badge,
			},
		},
	},
	Topic: "industry-tech",
}
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.",
    },
    Android = new AndroidConfig()
    {
        TimeToLive = TimeSpan.FromHours(1),
        Notification = new AndroidNotification()
        {
            Icon = "stock_ticker_update",
            Color = "#f45342",
        },
    },
    Apns = new ApnsConfig()
    {
        Aps = new Aps()
        {
            Badge = 42,
        },
    },
    Topic = "industry-tech",
};
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":"industry-tech",
     "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."
     },
     "android":{
       "notification":{
         "icon":"stock_ticker_update",
         "color":"#7e55c3"
       }
     }
   }
 }

See the HTTP v1 reference documentation for complete detail on the keys available in platform-specific blocks in the message body.

Example: notification message with a custom image

The following example send request sends a common notification title to all platforms, but it also sends an image. Here's an approximation of the visual effect on a user's device:

Simple drawing of an image in a display notification

Node.js বিশ্রাম
const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Sparky says hello!'
  },
  android: {
    notification: {
      imageUrl: 'https://foo.bar.pizza-monster.png'
    }
  },
  apns: {
    payload: {
      aps: {
        'mutable-content': 1
      }
    },
    fcm_options: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  webpush: {
    headers: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  topic: topicName,
};

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);
  });
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":"industry-tech",
     "notification":{
       "title":"Sparky says hello!",
     },
     "android":{
       "notification":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "mutable-content":1
         }
       },
       "fcm_options": {
           "image":"https://foo.bar/pizza-monster.png"
       }
     },
     "webpush":{
       "headers":{
         "image":"https://foo.bar/pizza-monster.png"
       }
     }
   }
 }

See the HTTP v1 reference documentation for complete detail on the keys available in platform-specific blocks in the message body.

Example: notification message with an associated click action

The following example send request sends a common notification title to all platforms, but it also sends an action for the app to perform in response to user interacting with the notification. Here's an approximation of the visual effect on a user's device:

Simple drawing of a user tap opening a web page

Node.js বিশ্রাম
const topicName = 'industry-tech';

const message = {
  notification: {
    title: 'Breaking News....'
  },
  android: {
    notification: {
      clickAction: 'news_intent'
    }
  },
  apns: {
    payload: {
      aps: {
        'category': 'INVITE_CATEGORY'
      }
    }
  },
  webpush: {
    fcmOptions: {
      link: 'breakingnews.html'
    }
  },
  topic: topicName,
};

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);
  });
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":"industry-tech",
     "notification":{
       "title":"Breaking News...",
     },
     "android":{
       "notification":{
         "click_action":"news_intent"
       }
     },
     "apns":{
       "payload":{
         "aps":{
           "category" : "INVITE_CATEGORY"
         }
       },
     },
     "webpush":{
       "fcm_options":{
         "link":"breakingnews.html"
       }
     }
   }
 }

See the HTTP v1 reference documentation for complete detail on the keys available in platform-specific blocks in the message body.

Example: notification message with localization options

The following example send request sends localization options for the client to display localized messages. Here's an approximation of the visual effect on a user's device:

Simple drawing of two devices displaying text in English and Spanish

Node.js বিশ্রাম
var topicName = 'industry-tech';

var message = {
  android: {
    ttl: 3600000,
    notification: {
      bodyLocKey: 'STOCK_NOTIFICATION_BODY',
      bodyLocArgs: ['FooCorp', '11.80', '835.67', '1.43']
    }
  },
  apns: {
    payload: {
      aps: {
        alert: {
          locKey: 'STOCK_NOTIFICATION_BODY',
          locArgs: ['FooCorp', '11.80', '835.67', '1.43']
        }
      }
    }
  },
  topic: topicName,
};

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);
  });
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":"Tech",
             "android":{
               "ttl":"3600s",
               "notification":{
                 "body_loc_key": "STOCK_NOTIFICATION_BODY",
                 "body_loc_args":  ["FooCorp", "11.80", "835.67", "1.43"],
               },
             },
             "apns":{
               "payload":{
                 "aps":{
                   "alert" : {
                     "loc-key": "STOCK_NOTIFICATION_BODY",
                     "loc-args":  ["FooCorp", "11.80", "835.67", "1.43"],
                    },
                 },
               },
             },
  },
}'

See the HTTP v1 reference documentation for complete detail on the keys available in platform-specific blocks in the message body.

REST error codes for the HTTP v1 API

HTTP error responses for the HTTP v1 API contain an error code, an error message, and error status. They may also contain a details array with more details on the error.

Here are two sample error responses:

Example 1: Error response from an HTTP v1 API request with an invalid value in a data message

{
  "error": {
    "code": 400,
    "message": "Invalid value at 'message.data[0].value' (TYPE_STRING), 12",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "message.data[0].value",
            "description": "Invalid value at 'message.data[0].value' (TYPE_STRING), 12"
          }
        ]
      }
    ]
  }
}

Example 2: Error response from an HTTP v1 API request with an invalid registration token

{
  "error": {
    "code": 400,
    "message": "The registration token is not a valid FCM registration token",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "INVALID_ARGUMENT"
      }
    ]
   }
}

Note that both messages have the same code and status, but the details array contains values in different types. The first example has type type.googleapis.com/google.rpc.BadRequest indicating an error in request values. The second example with type type.googleapis.com/google.firebase.fcm.v1.FcmError has an FCM specific error. For many errors, the details array contains the information you'll need to debug and find a resolution.

The following table lists the FCM v1 REST API error codes and their descriptions.

ত্রুটি কোড Description and Resolution Steps
UNSPECIFIED_ERROR No more information is available about this error. কোনোটিই নয়।
INVALID_ARGUMENT (HTTP error code = 400) Request parameters were invalid. An extension of type google.rpc.BadRequest is returned to specify which field was invalid. Potential causes include invalid registration, invalid package name, message too big, invalid data key, invalid TTL, or other invalid parameters.
Invalid registration : Check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with FCM. Do not truncate the token or add additional characters.
Invalid package name : Make sure the message was addressed to a registration token whose package name matches the value passed in the request.
Message too big : Check that the total size of the payload data included in a message does not exceed FCM limits: 4096 bytes for most messages, or 2048 bytes in the case of messages to topics. This includes both the keys and the values.
Invalid data key : Check that the payload data does not contain a key (such as from, or gcm, or any value prefixed by google) that is used internally by FCM. Note that some words (such as collapse_key) are also used by FCM but are allowed in the payload, in which case the payload value will be overridden by the FCM value.
Invalid TTL : Check that the value used in ttl is an integer representing a duration in seconds between 0 and 2,419,200 (4 weeks).
Invalid parameters : Check that the provided parameters have the right name and type.
UNREGISTERED (HTTP error code = 404) App instance was unregistered from FCM. This usually means that the token used is no longer valid and a new one must be used. This error can be caused by missing registration tokens, or unregistered tokens.
Missing Registration : If the message's target is a token value, check that the request contains a registration token.
Not registered : An existing registration token may cease to be valid in a number of scenarios, including:
- If the client app unregisters with FCM.
- If the client app is automatically unregistered, which can happen if the user uninstalls the application. For example, on iOS, if the APNs Feedback Service reported the APNs token as invalid.
- If the registration token expires (for example, Google might decide to refresh registration tokens, or the APNs token has expired for iOS devices).
- If the client app is updated but the new version is not configured to receive messages.
For all these cases, remove this registration token from the app server and stop using it to send messages.
SENDER_ID_MISMATCH (HTTP error code = 403) The authenticated sender ID is different from the sender ID for the registration token. A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.
QUOTA_EXCEEDED (HTTP error code = 429) Sending limit exceeded for the message target. An extension of type google.rpc.QuotaFailure is returned to specify which quota was exceeded. This error can be caused by exceeded message rate quota, exceeded device message rate quota, or exceeded topic message rate quota.
Message rate exceeded : The sending rate of messages is too high. You must reduce the overall rate at which you send messages. Use exponential backoff with a minimum initial delay of 1 minute to retry rejected messages.
Device message rate exceeded : The rate of messages to a particular device is too high. See message rate limit to a single device . Reduce the number of messages sent to this device and use exponential backoff to retry sending.
Topic message rate exceeded : The rate of messages to subscribers to a particular topic is too high. Reduce the number of messages sent for this topic and use exponential backoff with a minimum initial delay of 1 minute to retry sending.
UNAVAILABLE (HTTP error code = 503) The server is overloaded. The server couldn't process the request in time. Retry the same request, but you must:
- Honor the Retry-After header if it is included in the response from the FCM Connection Server.
- Implement exponential backoff in your retry mechanism. (eg if you waited one second before the first retry, wait at least two seconds before the next one, then 4 seconds and so on). If you're sending multiple messages, consider applying jittering. For more information, see Handling retries , or check the FCM status dashboard to identify if there are any ongoing service disruptions affecting FCM. Senders that cause problems risk being denylisted.
INTERNAL (HTTP error code = 500) An unknown internal error occurred. The server encountered an error while trying to process the request. You could retry the same request following suggestions in Handling retries or checking the FCM status dashboard . to identify if there are any ongoing service disruptions affecting FCM. If the error persists, please contact Firebase support.
THIRD_PARTY_AUTH_ERROR (HTTP error code = 401) APNs certificate or web push auth key was invalid or missing. A message targeted to an iOS device or a web push registration could not be sent. Check the validity of your development and production credentials.

Admin error codes

The following table lists the Firebase Admin FCM API error codes and their descriptions, including recommended resolution steps.

ত্রুটি কোড Description and Resolution Steps
messaging/invalid-argument An invalid argument was provided to an FCM method. The error message should contain additional information.
messaging/invalid-recipient The intended message recipient is invalid. The error message should contain additional information.
messaging/invalid-payload An invalid message payload object was provided. The error message should contain additional information.
messaging/invalid-data-payload-key The data message payload contains an invalid key. See the reference documentation for DataMessagePayload for restricted keys.
messaging/payload-size-limit-exceeded The provided message payload exceeds the FCM size limits. The limit is 4096 bytes for most messages. For messages sent to topics, the limit is 2048 bytes. The total payload size includes both keys and values.
messaging/invalid-options An invalid message options object was provided. The error message should contain additional information.
messaging/invalid-registration-token Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM . Do not truncate or add additional characters to it.
messaging/registration-token-not-registered The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons, including:
  • The client app unregistered itself from FCM .
  • The client app was automatically unregistered. This can happen if the user uninstalls the application or, on Apple platforms, if the APNs Feedback Service reported the APNs token as invalid.
  • The registration token expired. For example, Google might decide to refresh registration tokens or the APNs token may have expired for Apple devices.
  • The client app was updated, but the new version is not configured to receive messages.
For all these cases, remove this registration token and stop using it to send messages.
messaging/invalid-package-name The message was addressed to a registration token whose package name does not match the provided restrictedPackageName option.
messaging/message-rate-exceeded The rate of messages to a particular target is too high. Reduce the number of messages sent to this device or topic and do not immediately retry sending to this target.
messaging/device-message-rate-exceeded The rate of messages to a particular device is too high. Reduce the number of messages sent to this device and do not immediately retry sending to this device.
messaging/topics-message-rate-exceeded The rate of messages to subscribers to a particular topic is too high. Reduce the number of messages sent for this topic, and do not immediately retry sending to this topic.
messaging/too-many-topics A registration token has been subscribed to the maximum number of topics and cannot be subscribed to any more.
messaging/invalid-apns-credentials A message targeted to an Apple device could not be sent because the required APNs SSL certificate was not uploaded or has expired. Check the validity of your development and production certificates.
messaging/mismatched-credential The credential used to authenticate this SDK does not have permission to send messages to the device corresponding to the provided registration token. Make sure the credential and registration token both belong to the same Firebase project. See Add Firebase to your app for documentation on how to authenticate the Firebase Admin SDK s.
messaging/authentication-error The SDK could not authenticate to the FCM servers. Make sure you authenticate the Firebase Admin SDK with a credential which has the proper permissions to send FCM messages. See Add Firebase to your app for documentation on how to authenticate the Firebase Admin SDK s.
messaging/server-unavailable The FCM server could not process the request in time. You should retry the same request, but you must:
  • Honor the Retry-After header if it is included in the response from the FCM Connection Server.
  • Implement exponential back-off in your retry mechanism. For example, if you waited one second before the first retry, wait at least two seconds before the next one, then four seconds, and so on. If you're sending multiple messages, delay each one independently by an additional random amount to avoid issuing a new request for all messages at the same time.
Senders that cause problems risk being blacklisted.
messaging/internal-error The FCM server encountered an error while trying to process the request. You could retry the same request following the requirements listed in the messaging/server-unavailable row above. If the error persists, please report the problem to our Bug Report support channel.
messaging/unknown-error An unknown server error was returned. See the raw server response in the error message for more details. If you receive this error, please report the full error message to our Bug Report support channel.