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

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

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

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

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

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

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

Node.js

// 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টি পর্যন্ত ডিভাইস নিবন্ধন টোকেন নির্দিষ্ট করতে পারেন।

ফেরত মান টোকেনগুলির একটি তালিকা অন্তর্ভুক্ত করে যা ইনপুট টোকেনের ক্রম অনুসারে। এটি দরকারী যখন আপনি পরীক্ষা করতে চান যে কোন টোকেনগুলির ফলে ত্রুটি হয়েছে এবং তারপর সেগুলি যথাযথভাবে পরিচালনা করুন

Node.js

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

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

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

জাভা

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

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

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

পাইথন

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

message = messaging.MulticastMessage(
    data={'score': '850', 'time': '2:45'},
    tokens=registration_tokens,
)
response = messaging.send_each_for_multicast(message)
if response.failure_count > 0:
    responses = response.responses
    failed_tokens = []
    for idx, resp in enumerate(responses):
        if not resp.success:
            # The order of responses corresponds to the order of the registration tokens.
            failed_tokens.append(registration_tokens[idx])
    print('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.SendEachForMulticast(context.Background(), message)
if err != nil {
	log.Fatalln(err)
}

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

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

সি#

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

বার্তাগুলির একটি তালিকা পাঠান

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

Node.js

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

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

জাভা

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

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

পাইথন

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

response = messaging.send_each(messages)
# See the BatchResponse reference documentation
# for the contents of response.
print('{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.SendEach(context.Background(), messages)
if err != nil {
	log.Fatalln(err)
}

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

সি#

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

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

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

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

Node.js

// The topic name can be optionally prefixed with "/topics/".
const topic = 'highScores';

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

// Send a message to devices subscribed to the provided topic.
getMessaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

জাভা

// The topic name can be optionally prefixed with "/topics/".
String topic = "highScores";

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

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

পাইথন

# The topic name can be optionally prefixed with "/topics/".
topic = 'highScores'

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

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

যাও

// The topic name can be optionally prefixed with "/topics/".
topic := "highScores"

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

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

সি#

// The topic name can be optionally prefixed with "/topics/".
var topic = "highScores";

// See documentation on defining a message payload.
var message = new Message()
{
    Data = new Dictionary<string, string>()
    {
        { "score", "850" },
        { "time", "2:45" },
    },
    Topic = topic,
};

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

বিশ্রাম

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

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

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

Node.js

// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
const condition = '\'stock-GOOG\' in topics || \'industry-tech\' in topics';

// See documentation on defining a message payload.
const message = {
  notification: {
    title: '$FooCorp up 1.43% on the day',
    body: '$FooCorp gained 11.80 points to close at 835.67, up 1.43% on the day.'
  },
  condition: condition
};

// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
getMessaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

জাভা

// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
String condition = "'stock-GOOG' in topics || 'industry-tech' in topics";

// See documentation on defining a message payload.
Message message = Message.builder()
    .setNotification(Notification.builder()
        .setTitle("$GOOG up 1.43% on the day")
        .setBody("$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.")
        .build())
    .setCondition(condition)
    .build();

// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);

পাইথন

# Define a condition which will send to devices which are subscribed
# to either the Google stock or the tech industry topics.
condition = "'stock-GOOG' in topics || 'industry-tech' in topics"

# See documentation on defining a message payload.
message = messaging.Message(
    notification=messaging.Notification(
        title='$GOOG up 1.43% on the day',
        body='$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
    ),
    condition=condition,
)

# Send a message to devices subscribed to the combination of topics
# specified by the provided condition.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)

যাও

// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
condition := "'stock-GOOG' in topics || 'industry-tech' in topics"

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

// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
response, err := client.Send(ctx, message)
if err != nil {
	log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)

সি#

// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
var condition = "'stock-GOOG' in topics || 'industry-tech' in topics";

// See documentation on defining a message payload.
var message = new Message()
{
    Notification = new Notification()
    {
        Title = "$GOOG up 1.43% on the day",
        Body = "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.",
    },
    Condition = condition,
};

// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);

বিশ্রাম

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

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

একটি ডিভাইস গ্রুপে বার্তা পাঠানো একটি পৃথক ডিভাইসে বার্তা পাঠানোর অনুরূপ, একই পদ্ধতি ব্যবহার করে প্রেরণের অনুরোধ অনুমোদন করে ৷ গ্রুপ বিজ্ঞপ্তি কী 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 কমান্ড

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

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

আপনি 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 ফরম্যাটে নির্দিষ্ট করা হয়েছে এবং ছবিটি অবশ্যই অ্যান্ড্রয়েড অ্যাপের স্থানীয় আইকন রিসোর্স হতে হবে।

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

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

Node.js

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 রেফারেন্স ডকুমেন্টেশন দেখুন।