Catch up on highlights from Firebase at Google I/O 2023. Learn more

ऐप सर्वर बनाएं अनुरोध भेजें

Firebase Admin SDK या FCM ऐप सर्वर प्रोटोकॉल का उपयोग करके, आप संदेश अनुरोध बना सकते हैं और उन्हें इस प्रकार के लक्ष्यों को भेज सकते हैं:

  • विषय का नाम
  • स्थिति
  • डिवाइस पंजीकरण टोकन
  • डिवाइस समूह का नाम (लेगेसी प्रोटोकॉल और केवल Node.js के लिए Firebase Admin SDK)

आप पूर्वनिर्धारित फ़ील्ड से बने अधिसूचना पेलोड के साथ संदेश भेज सकते हैं, अपने स्वयं के यूज़र-डिफ़ाइंड फ़ील्ड के डेटा पेलोड या दोनों प्रकार के पेलोड वाले संदेश भेज सकते हैं। अधिक जानकारी के लिए संदेश प्रकार देखें।

इस पृष्ठ के उदाहरण दिखाते हैं कि Firebase Admin SDK (जिसमें Node , Java , Python , C# और Go का समर्थन है) और v1 HTTP प्रोटोकॉल का उपयोग करके सूचना संदेश कैसे भेजें। लीगेसी HTTP और XMPP प्रोटोकॉल के माध्यम से संदेश भेजने के लिए मार्गदर्शन भी है।

विशिष्ट उपकरणों को संदेश भेजें

किसी एकल, विशिष्ट डिवाइस को भेजने के लिए, दिखाए गए अनुसार डिवाइस का पंजीकरण टोकन पास करें। पंजीकरण टोकन के बारे में अधिक जानने के लिए अपने प्लेटफॉर्म के लिए क्लाइंट सेटअप जानकारी देखें।

नोड.जेएस

// 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 व्यवस्थापक SDK ID स्ट्रिंग को प्रारूप projects/{project_id}/messages/{message_id} में लौटाता है। HTTP प्रोटोकॉल प्रतिक्रिया एक एकल JSON कुंजी है:

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

एकाधिक उपकरणों पर संदेश भेजें

REST API और व्यवस्थापक FCM API आपको किसी संदेश को उपकरण पंजीकरण टोकन की सूची में मल्टीकास्ट करने की अनुमति देते हैं। आप प्रति आमंत्रण 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.SendMulticastAsync(message);
// See the BatchResponse reference documentation
// for the contents of response.
Console.WriteLine($"{response.SuccessCount} messages were sent successfully");

आराम

एक HTTP बैच अनुरोध बनाएँ:

--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary

POST /v1/projects/myproject-b5ae1/messages:send
Content-Type: application/json
accept: application/json

{
  "message":{
     "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
     "notification":{
       "title":"FCM Message",
       "body":"This is an FCM notification message!"
     }
  }
}

...

--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary

POST /v1/projects/myproject-b5ae1/messages:send
Content-Type: application/json
accept: application/json

{
  "message":{
     "token":"cR1rjyj4_Kc:APA91bGusqbypSuMdsh7jSNrW4nzsM...",
     "notification":{
       "title":"FCM Message",
       "body":"This is an FCM notification message!"
     }
  }
}
--subrequest_boundary--

अनुरोध को एक फ़ाइल में सहेजें (इस उदाहरण में बैच_request.txt)। फिर cURL कमांड का उपयोग करें:

curl --data-binary @batch_request.txt -H 'Content-Type: multipart/mixed; boundary="subrequest_boundary"' -H 'Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA' https://fcm.googleapis.com/batch

फायरबेस एडमिन एसडीके के लिए, यह ऑपरेशन हुड के तहत sendAll() एपीआई का उपयोग करता है, जैसा कि उदाहरणों में दिखाया गया है। रिटर्न वैल्यू एक BatchResponse है जिसकी प्रतिक्रिया सूची इनपुट टोकन के क्रम से मेल खाती है। यह तब उपयोगी होता है जब आप यह जांचना चाहते हैं कि किन टोकनों के परिणामस्वरूप त्रुटियां हुईं।

नोड.जेएस

// 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.SendMulticastAsync(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}");
}

आराम

प्रत्येक भेजें उप-भेजें प्रतिक्रिया देता है। प्रत्युत्तरों को --batch_ से शुरू होने वाली प्रतिक्रिया सीमा स्ट्रिंग द्वारा अलग किया जाता है।

--batch_nDhMX4IzFTDLsCJ3kHH7v_44ua-aJT6q
Content-Type: application/http
Content-ID: response-

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Vary: X-Origin
Vary: Referer

{
  "name": "projects/35006771263/messages/0:1570471792141125%43c11b7043c11b70"
}

...

--batch_nDhMX4IzFTDLsCJ3kHH7v_44ua-aJT6q
Content-Type: application/http
Content-ID: response-

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Vary: X-Origin
Vary: Referer

{
  "name": "projects/35006771263/messages/0:1570471792141696%43c11b7043c11b70"
}

--batch_nDhMX4IzFTDLsCJ3kHH7v_44ua-aJT6q--

विषयों को संदेश भेजें

आपके द्वारा एक विषय बनाने के बाद, या तो क्लाइंट साइड पर या सर्वर एपीआई के माध्यम से क्लाइंट ऐप इंस्टेंस की सदस्यता लेकर, आप विषय पर संदेश भेज सकते हैं। यदि आप पहली बार 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

संदेशों का एक बैच भेजें

REST API और व्यवस्थापक SDK बैचों में संदेश भेजने का समर्थन करते हैं। आप प्रत्येक संदेश के लिए अलग-अलग HTTP अनुरोध भेजने पर महत्वपूर्ण प्रदर्शन सुधार के साथ, एक ही बैच में अधिकतम 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.SendAllAsync(messages);
// See the BatchResponse reference documentation
// for the contents of response.
Console.WriteLine($"{response.SuccessCount} messages were sent successfully");

आराम

उप-अनुरोधों की सूची को मिलाकर एक HTTP बैच अनुरोध बनाएँ:

--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary

POST /v1/projects/myproject-b5ae1/messages:send
Content-Type: application/json
accept: application/json

{
  "message":{
     "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
     "notification":{
       "title":"FCM Message",
       "body":"This is an FCM notification message to device 0!"
     }
  }
}

--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary

POST /v1/projects/myproject-b5ae1/messages:send
Content-Type: application/json
accept: application/json

{
  "message":{
     "topic":"readers-club",
     "notification":{
       "title":"Price drop",
       "body":"2% off all books"
     }
  }
}

...

--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary

POST /v1/projects/myproject-b5ae1/messages:send
Content-Type: application/json
accept: application/json

{
  "message":{
     "token":"cR1rjyj4_Kc:APA91bGusqbypSuMdsh7jSNrW4nzsM...",
     "notification":{
       "title":"FCM Message",
       "body":"This is an FCM notification message to device N!"
     }
  }
}
--subrequest_boundary--

कितने संदेशों को सफलतापूर्वक FCM को सौंप दिया गया था, यह जांचने के लिए आप लौटाए गए BatchResponse क्वेरी कर सकते हैं। यह प्रतिक्रियाओं की एक सूची भी दिखाता है जिसका उपयोग व्यक्तिगत संदेशों की स्थिति की जांच के लिए किया जा सकता है। प्रतिक्रियाओं का क्रम इनपुट सूची में संदेशों के क्रम से मेल खाता है।

सीधे बूट-सक्षम संदेश भेजें (केवल Android)

आप HTTP v1 या लीगेसी HTTP APIs का उपयोग करके सीधे बूट मोड में उपकरणों को संदेश भेज सकते हैं। प्रत्यक्ष बूट मोड में उपकरणों को भेजने से पहले, सुनिश्चित करें कि आपने क्लाइंट उपकरणों को प्रत्यक्ष बूट मोड में FCM संदेशों को प्राप्त करने के लिए सक्षम करने के चरणों को पूरा कर लिया है।

FCM v1 HTTP API का उपयोग करके भेजें

संदेश अनुरोध में "direct_boot_ok" कुंजी शामिल होनी चाहिए: अनुरोध निकाय के 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,
    },
}

FCM लीगेसी HTTP API का उपयोग करके भेजें

संदेश अनुरोध में "direct_boot_ok" : true । उदाहरण के लिए:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

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

अनुरोध के मुख्य भाग में इस कुंजी के साथ भेजे गए संदेशों को वर्तमान में सीधे बूट मोड में (और उस मोड में नहीं होने पर भी) उपकरणों पर ऐप्स द्वारा नियंत्रित किया जा सकता है।

प्लेटफार्मों भर में संदेशों को अनुकूलित करें

Firebase Admin SDK और FCM v1 HTTP प्रोटोकॉल दोनों आपके संदेश अनुरोधों को message ऑब्जेक्ट में उपलब्ध सभी फ़ील्ड सेट करने की अनुमति देते हैं। यह भी शामिल है:

  • संदेश प्राप्त करने वाले सभी ऐप इंस्टेंस द्वारा व्याख्या किए जाने वाले फ़ील्ड का एक सामान्य सेट।
  • फ़ील्ड के प्लेटफ़ॉर्म-विशिष्ट सेट, जैसे कि AndroidConfig और WebpushConfig , केवल निर्दिष्ट प्लेटफ़ॉर्म पर चलने वाले ऐप इंस्टेंस द्वारा व्याख्या किए जाते हैं।

प्लेटफ़ॉर्म-विशिष्ट ब्लॉक आपको विभिन्न प्लेटफ़ॉर्म के लिए संदेशों को कस्टमाइज़ करने की सुविधा देते हैं ताकि यह सुनिश्चित हो सके कि प्राप्त होने पर उन्हें सही तरीके से हैंडल किया जा सके। FCM बैकएंड सभी निर्दिष्ट मापदंडों को ध्यान में रखेगा और प्रत्येक प्लेटफॉर्म के लिए संदेश को अनुकूलित करेगा।

सामान्य क्षेत्रों का उपयोग कब करें

सामान्य फ़ील्ड का उपयोग तब करें जब आप:

  • सभी प्लेटफ़ॉर्म — Apple, Android और वेब पर ऐप इंस्टेंस को लक्षित करना
  • विषयों पर संदेश भेजना

प्लेटफ़ॉर्म की परवाह किए बिना सभी ऐप इंस्टेंस, निम्नलिखित सामान्य फ़ील्ड की व्याख्या कर सकते हैं:

प्लेटफ़ॉर्म-विशिष्ट फ़ील्ड का उपयोग कब करें

जब आप चाहें तो प्लेटफ़ॉर्म-विशिष्ट फ़ील्ड का उपयोग करें:

  • फ़ील्ड केवल विशेष प्लेटफ़ॉर्म पर भेजें
  • सामान्य फ़ील्ड के अलावा प्लेटफ़ॉर्म-विशिष्ट फ़ील्ड भेजें

जब भी आप केवल विशेष प्लेटफॉर्म पर मान भेजना चाहते हैं, तो सामान्य फ़ील्ड का उपयोग न करें ; प्लेटफ़ॉर्म-विशिष्ट फ़ील्ड का उपयोग करें। उदाहरण के लिए, केवल Apple प्लेटफ़ॉर्म और वेब पर सूचना भेजने के लिए, लेकिन Android पर नहीं, आपको फ़ील्ड के दो अलग-अलग सेट का उपयोग करना होगा, एक Apple के लिए और दूसरा वेब के लिए।

जब आप विशिष्ट वितरण विकल्पों के साथ संदेश भेज रहे हों, तो उन्हें सेट करने के लिए प्लेटफ़ॉर्म-विशिष्ट फ़ील्ड का उपयोग करें। यदि आप चाहें तो प्रति प्लेटफॉर्म अलग-अलग मान निर्दिष्ट कर सकते हैं। हालाँकि, भले ही आप सभी प्लैटफ़ॉर्म पर अनिवार्य रूप से समान मान सेट करना चाहते हों, आपको प्लैटफ़ॉर्म-विशिष्ट फ़ील्ड का उपयोग करना चाहिए. ऐसा इसलिए है क्योंकि प्रत्येक प्लेटफ़ॉर्म मान को थोड़ा अलग तरीके से व्याख्या कर सकता है—उदाहरण के लिए, Android पर समय-से-लाइव को समाप्ति समय के रूप में सेकंड में सेट किया जाता है, जबकि Apple पर इसे समाप्ति तिथि के रूप में सेट किया जाता है।

उदाहरण: रंग और आइकन विकल्पों के साथ सूचना संदेश

यह उदाहरण भेजने का अनुरोध सभी प्लेटफ़ॉर्म पर एक सामान्य सूचना शीर्षक और सामग्री भेजता है, लेकिन यह Android उपकरणों को कुछ प्लेटफ़ॉर्म-विशिष्ट ओवरराइड भी भेजता है।

Android के लिए, अनुरोध Android उपकरणों पर प्रदर्शित करने के लिए एक विशेष आइकन और रंग सेट करता है। जैसा कि AndroidNotification के संदर्भ में उल्लेख किया गया है, रंग #rrggbb प्रारूप में निर्दिष्ट किया गया है, और छवि को Android ऐप के लिए स्थानीय रूप से आकर्षित करने योग्य आइकन संसाधन होना चाहिए।

यहां उपयोगकर्ता के डिवाइस पर विज़ुअल प्रभाव का अनुमान दिया गया है:

दो उपकरणों का सरल आरेखण, जिसमें से एक कस्टम आइकन और रंग प्रदर्शित करता है

नोड.जेएस

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 संदर्भ दस्तावेज़ देखें।

उदाहरण: एक कस्टम छवि के साथ सूचना संदेश

निम्न उदाहरण भेजें अनुरोध सभी प्लेटफ़ॉर्म पर एक सामान्य सूचना शीर्षक भेजता है, लेकिन यह एक छवि भी भेजता है। यहां उपयोगकर्ता के डिवाइस पर विज़ुअल प्रभाव का अनुमान दिया गया है:

एक प्रदर्शन सूचना में एक छवि का सरल आरेखण

नोड.जेएस

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 संदर्भ दस्तावेज़ देखें।

उदाहरण: संबंधित क्लिक क्रिया के साथ सूचना संदेश

निम्न उदाहरण भेजें अनुरोध सभी प्लेटफ़ॉर्म पर एक सामान्य सूचना शीर्षक भेजता है, लेकिन यह अधिसूचना के साथ इंटरैक्ट करने वाले उपयोगकर्ता के जवाब में प्रदर्शन करने के लिए ऐप के लिए एक क्रिया भी भेजता है। यहां उपयोगकर्ता के डिवाइस पर विज़ुअल प्रभाव का अनुमान दिया गया है:

एक वेब पेज खोलने वाले उपयोगकर्ता टैप का सरल आरेखण

नोड.जेएस

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 संदर्भ दस्तावेज़ देखें।

उदाहरण: स्थानीयकरण विकल्पों के साथ सूचना संदेश

निम्न उदाहरण भेजें अनुरोध क्लाइंट को स्थानीय संदेश प्रदर्शित करने के लिए स्थानीयकरण विकल्प भेजता है। यहां उपयोगकर्ता के डिवाइस पर विज़ुअल प्रभाव का अनुमान दिया गया है:

अंग्रेजी और स्पेनिश में पाठ प्रदर्शित करने वाले दो उपकरणों का सरल आरेखण

नोड.जेएस

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 संदर्भ दस्तावेज़ देखें।

व्यवस्थापक त्रुटि कोड

निम्न तालिका अनुशंसित समाधान चरणों सहित Firebase Admin 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 इस एसडीके को प्रमाणित करने के लिए उपयोग किए जाने वाले क्रेडेंशियल को प्रदान किए गए पंजीकरण टोकन से संबंधित डिवाइस को संदेश भेजने की अनुमति नहीं है। सुनिश्चित करें कि क्रेडेंशियल और पंजीकरण टोकन दोनों एक ही फायरबेस प्रोजेक्ट से संबंधित हैं। Firebase Admin SDKs को प्रमाणित करने के तरीके के दस्तावेज़ीकरण के लिए अपने ऐप में Firebase जोड़ें देखें।
messaging/authentication-error एसडीके एफसीएम सर्वरों को प्रमाणित नहीं कर सका। सुनिश्चित करें कि आपने फायरबेस एडमिन एसडीके को एक क्रेडेंशियल के साथ प्रमाणित किया है जिसके पास एफसीएम संदेश भेजने के लिए उचित अनुमतियां हैं। Firebase Admin SDKs को प्रमाणित करने के तरीके के दस्तावेज़ीकरण के लिए अपने ऐप में Firebase जोड़ें देखें।
messaging/server-unavailable FCM सर्वर अनुरोध को समय पर संसाधित नहीं कर सका। आपको उसी अनुरोध का पुनः प्रयास करना चाहिए, लेकिन आपको यह अवश्य करना चाहिए:
  • Retry-After हेडर का सम्मान करें यदि यह FCM कनेक्शन सर्वर से प्रतिक्रिया में शामिल है।
  • अपने पुनर्प्रयास तंत्र में घातीय बैक-ऑफ लागू करें। उदाहरण के लिए, यदि आपने पहले पुन: प्रयास से पहले एक सेकंड प्रतीक्षा की, तो अगले एक से पहले कम से कम दो सेकंड, फिर चार सेकंड, और इसी तरह प्रतीक्षा करें। यदि आप एक से अधिक संदेश भेज रहे हैं, तो एक ही समय में सभी संदेशों के लिए एक नया अनुरोध जारी करने से बचने के लिए प्रत्येक को एक अतिरिक्त यादृच्छिक राशि से स्वतंत्र रूप से विलंबित करें।
समस्याएँ पैदा करने वाले प्रेषकों को काली सूची में डाले जाने का जोखिम होता है।
messaging/internal-error अनुरोध को संसाधित करने का प्रयास करते समय FCM सर्वर में त्रुटि आई। उपरोक्त messaging/server-unavailable पंक्ति में सूचीबद्ध आवश्यकताओं के बाद आप उसी अनुरोध का पुनः प्रयास कर सकते हैं। यदि त्रुटि बनी रहती है, तो कृपया हमारे बग रिपोर्ट समर्थन चैनल को समस्या की रिपोर्ट करें।
messaging/unknown-error एक अज्ञात सर्वर त्रुटि लौटाई गई थी। अधिक विवरण के लिए त्रुटि संदेश में अपरिष्कृत सर्वर प्रतिक्रिया देखें। यदि आपको यह त्रुटि प्राप्त होती है, तो कृपया हमारे बग रिपोर्ट समर्थन चैनल को पूर्ण त्रुटि संदेश की रिपोर्ट करें।

लीगेसी ऐप सर्वर प्रोटोकॉल का उपयोग करके संदेश भेजें

यदि आप लीगेसी प्रोटोकॉल का उपयोग करना पसंद करते हैं, तो इस खंड में दिखाए अनुसार संदेश अनुरोध बनाएं। ध्यान रखें कि, अगर आप एचटीटीपी के ज़रिए कई प्लैटफ़ॉर्म पर भेज रहे हैं, तो v1 प्रोटोकॉल आपके मैसेज अनुरोधों को आसान बना सकता है.

विशिष्ट उपकरणों को संदेश भेजें

विशिष्ट उपकरणों को संदेश भेजने के लिए, विशिष्ट ऐप इंस्टेंस के लिए पंजीकरण टोकन के लिए to सेट करें। पंजीकरण टोकन के बारे में अधिक जानने के लिए अपने प्लेटफॉर्म के लिए क्लाइंट सेटअप जानकारी देखें।

HTTP पोस्ट अनुरोध

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

HTTP प्रतिक्रिया

{ "multicast_id": 108,
  "success": 1,
  "failure": 0,
  "results": [
    { "message_id": "1:08" }
  ]
}

एक्सएमपीपी संदेश

<message id="">
  <gcm xmlns="google:mobile:data">
    { "data": {
      "score": "5x1",
      "time": "15:10"
    },
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
  }
  </gcm>
</message>

एक्सएमपीपी प्रतिक्रिया

<message id="">
  <gcm xmlns="google:mobile:data">
  {
      "from":"REGID",
      "message_id":"m-1366082849205"
      "message_type":"ack"
  }
  </gcm>
</message>

XMPP कनेक्शन सर्वर प्रतिक्रिया के लिए कुछ अन्य विकल्प प्रदान करता है। सर्वर प्रतिक्रिया प्रारूप देखें।

क्लाइंट ऐप्स को डाउनस्ट्रीम संदेश भेजते समय उपलब्ध संदेश विकल्पों की पूरी सूची के लिए, अपने चुने हुए कनेक्शन सर्वर प्रोटोकॉल, HTTP या XMPP के लिए संदर्भ जानकारी देखें।

विषयों को संदेश भेजें

फायरबेस क्लाउड मैसेजिंग विषय पर संदेश भेजना एक व्यक्तिगत डिवाइस या उपयोगकर्ता समूह को संदेश भेजने के समान है। ऐप सर्वर कुंजी to /topics/yourTopic जैसे मान के साथ सेट करता है। डेवलपर कोई भी विषय नाम चुन सकते हैं जो रेगुलर एक्सप्रेशन से मेल खाता हो: "/topics/[a-zA-Z0-9-_.~%]+"

एकाधिक विषयों के संयोजनों को भेजने के लिए, ऐप सर्वर को एक बूलियन शर्त के लिए condition कुंजी ( to के बजाय) सेट करनी होगी जो लक्ष्य विषयों को निर्दिष्ट करती है। उदाहरण के लिए, TopicA और TopicB या TopicC की सदस्यता लेने वाले उपकरणों को संदेश भेजने के लिए:

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

FCM पहले कोष्ठकों में किसी भी स्थिति का मूल्यांकन करता है, और फिर बाएँ से दाएँ अभिव्यक्ति का मूल्यांकन करता है। उपरोक्त अभिव्यक्ति में, किसी एक विषय की सदस्यता लेने वाले उपयोगकर्ता को संदेश प्राप्त नहीं होता है। इसी तरह, एक उपयोगकर्ता जो TopicA की सदस्यता नहीं लेता है, उसे संदेश प्राप्त नहीं होता है। ये संयोजन इसे प्राप्त करते हैं:

  • टॉपिक ए और टॉपिक बी
  • टॉपिक ए और टॉपिक सी

आप अपनी सशर्त अभिव्यक्ति में अधिकतम पांच विषय शामिल कर सकते हैं, और कोष्ठक समर्थित हैं। समर्थित ऑपरेटर्स: && , || .

विषय HTTP पोस्ट अनुरोध

एक ही विषय पर भेजें:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA


"कुत्तों" या "बिल्लियों" विषयों की सदस्यता लेने वाले उपकरणों को भेजें:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA


विषय HTTP प्रतिक्रिया

//Success example:
{
  "message_id": "1023456"
}

//failure example:
{
  "error": "TopicsMessageRateExceeded"
}

विषय XMPP संदेश

एक ही विषय पर भेजें:

<message id="">
  <gcm xmlns="google:mobile:data">


  </gcm>
</message>

"कुत्तों" या "बिल्लियों" विषयों की सदस्यता लेने वाले उपकरणों को भेजें:

<message id="">
  <gcm xmlns="google:mobile:data">


  </gcm>
</message>

विषय XMPP प्रतिक्रिया

//Success example:
{
  "message_id": "1023456"
}

//failure example:
{
  "error": "TopicsMessageRateExceeded"
}

अनुरोध भेजने वाले विषय पर FCM सर्वर द्वारा सफलता या विफलता प्रतिक्रिया देने से पहले 30 सेकंड तक की देरी की अपेक्षा करें। तदनुसार अनुरोध में ऐप सर्वर का टाइमआउट मान सेट करना सुनिश्चित करें।

उपकरण समूहों को संदेश भेजें

किसी डिवाइस समूह को संदेश भेजना किसी व्यक्तिगत डिवाइस पर संदेश भेजने के समान ही है। डिवाइस समूह के लिए अद्वितीय अधिसूचना कुंजी to लिए पैरामीटर सेट करें। पेलोड समर्थन पर विवरण के लिए संदेश प्रकार देखें। इस पृष्ठ के उदाहरण दिखाते हैं कि लीगेसी HTTP और XMPP प्रोटोकॉल में डिवाइस समूहों को डेटा संदेश कैसे भेजें।

डिवाइस समूह HTTP पोस्ट अनुरोध

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{
  "to": "aUniqueKey",
  "data": {
    "hello": "This is a Firebase Cloud Messaging Device Group Message!",
   }
}

डिवाइस समूह HTTP प्रतिसाद

यहां "सफलता" का एक उदाहरण दिया गया है - notification_key इसके साथ 2 पंजीकरण टोकन जुड़े हुए हैं, और संदेश सफलतापूर्वक उन दोनों को भेजा गया था:

{
  "success": 2,
  "failure": 0
}

यहां "आंशिक सफलता" का एक उदाहरण दिया गया है - notification_key के साथ 3 पंजीकरण टोकन जुड़े हुए हैं। संदेश केवल 1 पंजीकरण टोकन को सफलतापूर्वक भेजा गया था। प्रतिक्रिया संदेश पंजीकरण टोकन ( registration_ids ) को सूचीबद्ध करता है जो संदेश प्राप्त करने में विफल रहा:

{
  "success":1,
  "failure":2,
  "failed_registration_ids":[
     "regId1",
     "regId2"
  ]
}

जब कोई संदेश notification_key से जुड़े एक या अधिक पंजीकरण टोकन को वितरित करने में विफल रहता है, तो ऐप सर्वर को पुनर्प्रयास के बीच बैकऑफ़ के साथ पुनः प्रयास करना चाहिए।

यदि सर्वर किसी ऐसे उपकरण समूह को संदेश भेजने का प्रयास करता है जिसमें कोई सदस्य नहीं है, तो प्रतिक्रिया निम्न की तरह दिखती है, जिसमें 0 सफलता और 0 विफलता होती है:

{
  "success": 0,
  "failure": 0
}

डिवाइस समूह XMPP संदेश

<message id="">
  <gcm xmlns="google:mobile:data">
  {
      "to": "aUniqueKey",
      "message_id": "m-1366082849205" ,
      "data": {
          "hello":"This is a Firebase Cloud Messaging Device Group Message!"
      }
  }
  </gcm>
</message>

डिवाइस समूह XMPP प्रतिक्रिया

जब समूह में किसी एक डिवाइस को संदेश सफलतापूर्वक भेजा जाता है, तो XMPP कनेक्शन सर्वर ACK के साथ प्रतिक्रिया करता है। यदि समूह में सभी उपकरणों को भेजे गए सभी संदेश विफल हो जाते हैं, तो XMPP कनेक्शन सर्वर NACK के साथ प्रतिक्रिया करता है।

यहां "सफलता" का एक उदाहरण दिया गया है - notification_key के साथ 3 पंजीकरण टोकन जुड़े हुए हैं, और उन सभी को संदेश सफलतापूर्वक भेजा गया था:

{
  "from": "aUniqueKey",
  "message_type": "ack",
  "success": 3,
  "failure": 0,
  "message_id": "m-1366082849205"
}

यहां "आंशिक सफलता" का एक उदाहरण दिया गया है - notification_key के साथ 3 पंजीकरण टोकन जुड़े हुए हैं। संदेश केवल 1 पंजीकरण टोकन को सफलतापूर्वक भेजा गया था। प्रतिक्रिया संदेश उन पंजीकरण टोकनों को सूचीबद्ध करता है जो संदेश प्राप्त करने में विफल रहे:

{
  "from": "aUniqueKey",
  "message_type": "ack",
  "success":1,
  "failure":2,
  "failed_registration_ids":[
     "regId1",
     "regId2"
  ]
}

जब FCM कनेक्शन सर्वर समूह में सभी उपकरणों को डिलीवर करने में विफल रहता है। ऐप सर्वर को एक नैक प्रतिक्रिया प्राप्त होगी।

संदेश विकल्पों की पूरी सूची के लिए, अपने चुने हुए कनेक्शन सर्वर प्रोटोकॉल, HTTP या XMPP के लिए संदर्भ जानकारी देखें।

फायरबेस एडमिन एसडीके लीगेसी भेजने के तरीके

Firebase Admin Node.js SDK लीगेसी FCM सर्वर API के आधार पर (FCM) संदेश भेजने के तरीकों का समर्थन करता है। send() विधि की तुलना में ये विधियाँ विभिन्न तर्कों को स्वीकार करती हैं। आपको जब भी संभव हो send() विधि का उपयोग करना चाहिए, और केवल इस पृष्ठ में वर्णित विधियों का उपयोग व्यक्तिगत उपकरणों या डिवाइस समूहों को संदेश भेजते समय करना चाहिए।

व्यक्तिगत उपकरणों को भेजें

आप उस डिवाइस पर एक संदेश भेजने के लिए sendToDevice() विधि में एक पंजीकरण टोकन पास कर सकते हैं:

नोड.जेएस

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

// See the "Defining the message payload" section below for details
// on how to define a message payload.
const payload = {
  data: {
    score: '850',
    time: '2:45'
  }
};

// Send a message to the device corresponding to the provided
// registration token.
getMessaging().sendToDevice(registrationToken, payload)
  .then((response) => {
    // See the MessagingDevicesResponse reference documentation for
    // the contents of response.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

sendToDevice() विधि केवल एक पंजीकरण टोकन के बजाय पंजीकरण टोकन की एक सरणी पास करके एक मल्टीकास्ट संदेश (यानी, कई उपकरणों के लिए एक संदेश) भेज सकती है:

नोड.जेएस

// These registration tokens come from the client FCM SDKs.
const registrationTokens = [
  'bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...',
  // ...
  'ecupwIfBy1w:APA91bFtuMY7MktgxA3Au_Qx7cKqnf...'
];

// See the "Defining the message payload" section below for details
// on how to define a message payload.
const payload = {
  data: {
    score: '850',
    time: '2:45'
  }
};

// Send a message to the devices corresponding to the provided
// registration tokens.
getMessaging().sendToDevice(registrationTokens, payload)
  .then((response) => {
    // See the MessagingDevicesResponse reference documentation for
    // the contents of response.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

sendToDevice() विधि एक वादा देता है जिसे FCM से प्रतिक्रिया वाले MessagingDevicesResponse ऑब्जेक्ट के साथ हल किया जाता है। एकल पंजीकरण टोकन या पंजीकरण टोकन की एक सरणी पास करते समय रिटर्न प्रकार का प्रारूप समान होता है।

प्रमाणीकरण त्रुटि या दर सीमित करने जैसे कुछ मामले संदेश की संपूर्णता को संसाधित करने में विफल होने का कारण बनते हैं। इन मामलों में, sendToDevice() द्वारा लौटाए गए वादे को एक त्रुटि के साथ खारिज कर दिया जाता है। वर्णन और समाधान चरणों सहित त्रुटि कोड की पूरी सूची के लिए, व्यवस्थापक FCM API त्रुटियाँ देखें.

डिवाइस समूह को भेजें

डिवाइस समूह मैसेजिंग आपको एक ही समूह में कई डिवाइस जोड़ने की अनुमति देता है। यह विषय संदेश के समान है, लेकिन यह सुनिश्चित करने के लिए प्रमाणीकरण शामिल है कि समूह सदस्यता केवल आपके सर्वर द्वारा प्रबंधित की जाती है। उदाहरण के लिए, यदि आप अलग-अलग फोन मॉडल को अलग-अलग संदेश भेजना चाहते हैं, तो आपके सर्वर उपयुक्त समूहों में पंजीकरण जोड़/हटा सकते हैं और प्रत्येक समूह को उपयुक्त संदेश भेज सकते हैं। डिवाइस ग्रुप मैसेजिंग विषय मैसेजिंग से इस मायने में अलग है कि इसमें सीधे आपके एप्लिकेशन के बजाय आपके सर्वर से डिवाइस ग्रुप को प्रबंधित करना शामिल है।

आप अपने ऐप सर्वर पर लीगेसी XMPP या HTTP प्रोटोकॉल के माध्यम से डिवाइस ग्रुप मैसेजिंग का उपयोग कर सकते हैं। Node.js के लिए Firebase Admin SDK के पुराने संस्करण लीगेसी प्रोटोकॉल पर आधारित हैं और डिवाइस ग्रुप मैसेजिंग क्षमताएं भी प्रदान करते हैं। अधिसूचना कुंजी के लिए अनुमत सदस्यों की अधिकतम संख्या 20 है।

आप ऐप सर्वर या एंड्रॉइड क्लाइंट के माध्यम से डिवाइस समूह बना सकते हैं और अधिसूचना कुंजी उत्पन्न कर सकते हैं। विवरण के लिए डिवाइस समूह प्रबंधित करना देखें।

sendToDeviceGroup() विधि आपको उस डिवाइस समूह के लिए अधिसूचना कुंजी निर्दिष्ट करके डिवाइस समूह को एक संदेश भेजने की अनुमति देती है:

नोड.जेएस

// See the "Managing device groups" link above on how to generate a
// notification key.
const notificationKey = 'some-notification-key';

// See the "Defining the message payload" section below for details
// on how to define a message payload.
const payload = {
  data: {
    score: '850',
    time: '2:45'
  }
};

// Send a message to the device group corresponding to the provided
// notification key.
getMessaging().sendToDeviceGroup(notificationKey, payload)
  .then((response) => {
    // See the MessagingDeviceGroupResponse reference documentation for
    // the contents of response.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

sendToDeviceGroup() विधि एक वादा देता है जिसे FCM से प्रतिक्रिया वाले MessagingDevicesResponse ऑब्जेक्ट के साथ हल किया जाता है।

प्रमाणीकरण त्रुटि या दर सीमित करने जैसे कुछ मामले संदेश की संपूर्णता को संसाधित करने में विफल होने का कारण बनते हैं। इन मामलों में, sendToDeviceGroup() द्वारा लौटाए गए वादे को एक त्रुटि के साथ खारिज कर दिया जाता है। वर्णन और समाधान चरणों सहित त्रुटि कोड की पूरी सूची के लिए, व्यवस्थापक FCM API त्रुटियाँ देखें.

संदेश पेलोड को परिभाषित करना

FCM लीगेसी प्रोटोकॉल पर आधारित उपरोक्त विधियाँ संदेश पेलोड को उनके दूसरे तर्क के रूप में स्वीकार करती हैं और सूचना और डेटा संदेशों दोनों का समर्थन करती हैं। आप data और/या notification कुंजियों के साथ ऑब्जेक्ट बनाकर एक या दोनों संदेश प्रकार निर्दिष्ट कर सकते हैं। उदाहरण के लिए, यहां विभिन्न प्रकार के संदेश पेलोड को परिभाषित करने का तरीका बताया गया है:

सूचना संदेश

const payload = {
  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.'
  }
};

डेटा संदेश

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

संयुक्त संदेश

const payload = {
  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.'
  },
  data: {
    stock: 'GOOG',
    open: '829.62',
    close: '635.67'
  }
};

अधिसूचना संदेश पेलोड में मान्य गुणों का एक पूर्वनिर्धारित उपसमुच्चय होता है और आप जिस मोबाइल ऑपरेटिंग सिस्टम को लक्षित कर रहे हैं, उसके आधार पर यह थोड़ा भिन्न होता है। पूरी सूची के लिए NotificationMessagePayload के संदर्भ दस्तावेज़ देखें।

डेटा संदेश पेलोड कुछ प्रतिबंधों के साथ कस्टम की-वैल्यू जोड़े से बने होते हैं, जिसमें यह तथ्य भी शामिल है कि सभी मान स्ट्रिंग्स होने चाहिए। प्रतिबंधों की पूरी सूची के लिए DataMessagePayload के संदर्भ दस्तावेज़ देखें।

संदेश विकल्पों को परिभाषित करना

FCM लीगेसी प्रोटोकॉल पर आधारित उपरोक्त विधियाँ संदेश के लिए कुछ विकल्पों को निर्दिष्ट करते हुए एक वैकल्पिक तीसरा तर्क स्वीकार करती हैं। उदाहरण के लिए, निम्न उदाहरण एक डिवाइस को उच्च प्राथमिकता वाला संदेश भेजता है जो 24 घंटों के बाद समाप्त हो जाता है:

नोड.जेएस

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

// See the "Defining the message payload" section above for details
// on how to define a message payload.
const payload = {
  notification: {
    title: 'Urgent action needed!',
    body: 'Urgent action is needed to prevent your account from being disabled!'
  }
};

// Set the message as high priority and have it expire after 24 hours.
const options = {
  priority: 'high',
  timeToLive: 60 * 60 * 24
};

// Send a message to the device corresponding to the provided
// registration token with the provided options.
getMessaging().sendToDevice(registrationToken, payload, options)
  .then((response) => {
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

उपलब्ध विकल्पों की पूरी सूची के लिए MessagingOptions के संदर्भ दस्तावेज़ देखें।