Apple প্ল্যাটফর্মে একাধিক ডিভাইসে বার্তা পাঠান

একাধিক ডিভাইসে একটি বার্তা লক্ষ্য করতে, টপিক মেসেজিং ব্যবহার করুন। এই বৈশিষ্ট্যটি আপনাকে একাধিক ডিভাইসে একটি বার্তা পাঠাতে দেয় যারা একটি নির্দিষ্ট বিষয়ে নির্বাচন করেছে।

এই টিউটোরিয়ালটি FCM এর জন্য Admin SDK অথবা REST API ব্যবহার করে আপনার অ্যাপ সার্ভার থেকে বিষয়ভিত্তিক বার্তা পাঠানো এবং একটি Apple অ্যাপে সেগুলি গ্রহণ এবং পরিচালনা করার উপর আলোকপাত করে। এই পৃষ্ঠায় সেটআপ থেকে যাচাইকরণ পর্যন্ত সমস্ত পদক্ষেপ তালিকাভুক্ত করা হয়েছে - তাই এটি FCM জন্য একটি Apple ক্লায়েন্ট অ্যাপ সেট আপ করে থাকলে বা আপনার প্রথম বার্তা পাঠানোর পদক্ষেপগুলি সম্পন্ন করলে আপনি ইতিমধ্যেই সম্পন্ন করা পদক্ষেপগুলি অন্তর্ভুক্ত করতে পারে।

আপনার অ্যাপল প্রকল্পে ফায়ারবেস যোগ করুন

এই বিভাগটি আপনার অ্যাপের জন্য অন্যান্য Firebase বৈশিষ্ট্যগুলি সক্ষম করে থাকলে আপনি যে কাজগুলি সম্পন্ন করেছেন সেগুলি সম্পর্কে আলোচনা করে। বিশেষ করে FCM জন্য, আপনাকে আপনার APN প্রমাণীকরণ কী আপলোড করতে হবে এবং দূরবর্তী বিজ্ঞপ্তিগুলির জন্য নিবন্ধন করতে হবে

পূর্বশর্ত

  • নিম্নলিখিতগুলি ইনস্টল করুন:

    • এক্সকোড ১৬.২ বা তার পরবর্তী সংস্করণ
  • আপনার প্রকল্পটি এই প্রয়োজনীয়তাগুলি পূরণ করে তা নিশ্চিত করুন:

    • আপনার প্রকল্পটি অবশ্যই এই প্ল্যাটফর্ম সংস্করণগুলি বা তার পরবর্তী সংস্করণগুলিকে লক্ষ্য করবে:
      • আইওএস ১৩
      • ম্যাকওএস ১০.১৫
      • টিভিওএস ১৩
      • ওয়াচওএস ৭
  • আপনার অ্যাপ চালানোর জন্য একটি বাস্তব অ্যাপল ডিভাইস সেট আপ করুন এবং এই কাজগুলি সম্পন্ন করুন:

যদি আপনার কাছে ইতিমধ্যেই কোনও Xcode প্রকল্প না থাকে এবং শুধুমাত্র একটি Firebase পণ্য চেষ্টা করে দেখতে চান, তাহলে আপনি আমাদের কুইকস্টার্ট নমুনাগুলির একটি ডাউনলোড করতে পারেন।

একটি ফায়ারবেস প্রকল্প তৈরি করুন

আপনার অ্যাপল অ্যাপে Firebase যোগ করার আগে, আপনার অ্যাপের সাথে সংযোগ স্থাপনের জন্য আপনাকে একটি Firebase প্রকল্প তৈরি করতে হবে। Firebase প্রকল্প সম্পর্কে আরও জানতে Understand Firebase প্রকল্পগুলি দেখুন।

Firebase-এ আপনার অ্যাপ নিবন্ধন করুন

আপনার অ্যাপল অ্যাপে ফায়ারবেস ব্যবহার করার জন্য, আপনাকে আপনার ফায়ারবেস প্রোজেক্টের সাথে আপনার অ্যাপটি নিবন্ধন করতে হবে। আপনার অ্যাপটি নিবন্ধন করাকে প্রায়শই আপনার প্রোজেক্টে আপনার অ্যাপটি "যোগ করা" বলা হয়।

  1. Firebase কনসোলে যান।

  2. প্রজেক্ট ওভারভিউ পৃষ্ঠার মাঝখানে, সেটআপ ওয়ার্কফ্লো চালু করতে iOS+ আইকনে ক্লিক করুন।

    যদি আপনি ইতিমধ্যেই আপনার Firebase প্রকল্পে একটি অ্যাপ যোগ করে থাকেন, তাহলে প্ল্যাটফর্ম বিকল্পগুলি প্রদর্শন করতে অ্যাপ যোগ করুন- এ ক্লিক করুন।

  3. বান্ডেল আইডি ক্ষেত্রে আপনার অ্যাপের বান্ডেল আইডি লিখুন।

  4. (ঐচ্ছিক) অন্যান্য অ্যাপ তথ্য লিখুন: অ্যাপের ডাকনাম এবং অ্যাপ স্টোর আইডি

  5. অ্যাপ নিবন্ধন করুন এ ক্লিক করুন।

একটি Firebase কনফিগারেশন ফাইল যোগ করুন

  1. আপনার অ্যাপের Firebase কনফিগারেশন ফাইল ( GoogleService-Info.plist ) পেতে Download GoogleService-Info.plist এ ক্লিক করুন।

  2. আপনার কনফিগ ফাইলটি আপনার Xcode প্রজেক্টের রুটে সরান। যদি অনুরোধ করা হয়, তাহলে সমস্ত টার্গেটে কনফিগ ফাইল যোগ করতে নির্বাচন করুন।

যদি আপনার প্রোজেক্টে একাধিক বান্ডেল আইডি থাকে, তাহলে আপনাকে প্রতিটি বান্ডেল আইডি Firebase কনসোলে একটি নিবন্ধিত অ্যাপের সাথে সংযুক্ত করতে হবে যাতে প্রতিটি অ্যাপের নিজস্ব GoogleService-Info.plist ফাইল থাকতে পারে।

আপনার অ্যাপে Firebase SDK যোগ করুন

ফায়ারবেস নির্ভরতা ইনস্টল এবং পরিচালনা করতে সুইফট প্যাকেজ ম্যানেজার ব্যবহার করুন।

  1. Xcode-এ, আপনার অ্যাপ প্রজেক্ট খোলা থাকা অবস্থায়, File > Add Packages- এ নেভিগেট করুন।
  2. অনুরোধ করা হলে, Firebase Apple platforms SDK সংগ্রহস্থল যোগ করুন:
  3.   https://github.com/firebase/firebase-ios-sdk.git
  4. Firebase Cloud Messaging লাইব্রেরিটি বেছে নিন।
  5. আপনার টার্গেটের বিল্ড সেটিংসের অন্যান্য লিঙ্কার ফ্ল্যাগ বিভাগে -ObjC ফ্ল্যাগ যোগ করুন।
  6. Firebase Cloud Messaging এর সর্বোত্তম অভিজ্ঞতার জন্য, আমরা আপনার Firebase প্রোজেক্টে Google Analytics সক্ষম করার এবং আপনার অ্যাপে Google Analytics এর জন্য Firebase SDK যোগ করার পরামর্শ দিচ্ছি। আপনি IDFA সংগ্রহ ছাড়াই অথবা IDFA সংগ্রহ সহ লাইব্রেরি নির্বাচন করতে পারেন। Firebase SDK এর জন্য Google Analytics এর সর্বশেষ মডিউল সংগঠন সম্পর্কে আমাদের প্রায়শই জিজ্ঞাসিত প্রশ্নাবলী দেখুন।
  7. শেষ হয়ে গেলে, Xcode স্বয়ংক্রিয়ভাবে ব্যাকগ্রাউন্ডে আপনার নির্ভরতাগুলি সমাধান এবং ডাউনলোড করা শুরু করবে।

আপনার APN প্রমাণীকরণ কী আপলোড করুন

আপনার APN প্রমাণীকরণ কী Firebase-এ আপলোড করুন। যদি আপনার কাছে ইতিমধ্যেই একটি APN প্রমাণীকরণ কী না থাকে, তাহলে Apple Developer Member Center- এ একটি তৈরি করতে ভুলবেন না।

  1. Firebase কনসোলে আপনার প্রোজেক্টের ভিতরে, গিয়ার আইকনটি নির্বাচন করুন, প্রোজেক্ট সেটিংস নির্বাচন করুন এবং তারপর ক্লাউড মেসেজিং ট্যাবটি নির্বাচন করুন।

  2. iOS অ্যাপ কনফিগারেশনের অধীনে APNs প্রমাণীকরণ কী- তে, আপনার ডেভেলপমেন্ট প্রমাণীকরণ কী, অথবা প্রোডাকশন প্রমাণীকরণ কী, অথবা উভয়ই আপলোড করতে আপলোড বোতামে ক্লিক করুন। কমপক্ষে একটি প্রয়োজন।

  3. আপনার কী যেখানে সংরক্ষণ করেছেন সেই স্থানে ব্রাউজ করুন, এটি নির্বাচন করুন এবং খুলুন ক্লিক করুন। কীটির জন্য কী আইডি যোগ করুন ( অ্যাপল ডেভেলপার সদস্য কেন্দ্রে উপলব্ধ) এবং আপলোড ক্লিক করুন।

আপনার অ্যাপে Firebase আরম্ভ করুন

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

  1. আপনার UIApplicationDelegateFirebaseCore মডিউলটি আমদানি করুন, সেইসাথে আপনার অ্যাপ প্রতিনিধিদের দ্বারা ব্যবহৃত অন্য যেকোনো Firebase মডিউল । উদাহরণস্বরূপ, Cloud Firestore এবং Authentication ব্যবহার করতে:

    সুইফটইউআই

    import SwiftUI
    import FirebaseCore
    import FirebaseFirestore
    import FirebaseAuth
    // ...
          

    সুইফট

    import FirebaseCore
    import FirebaseFirestore
    import FirebaseAuth
    // ...
          

    অবজেক্টিভ-সি

    @import FirebaseCore;
    @import FirebaseFirestore;
    @import FirebaseAuth;
    // ...
          
  2. আপনার অ্যাপ ডেলিগেটের application(_:didFinishLaunchingWithOptions:) পদ্ধতিতে একটি FirebaseApp শেয়ার করা ইনস্ট্যান্স কনফিগার করুন:

    সুইফটইউআই

    // Use Firebase library to configure APIs
    FirebaseApp.configure()

    সুইফট

    // Use Firebase library to configure APIs
    FirebaseApp.configure()

    অবজেক্টিভ-সি

    // Use Firebase library to configure APIs
    [FIRApp configure];
  3. যদি আপনি SwiftUI ব্যবহার করেন, তাহলে আপনাকে একটি অ্যাপ্লিকেশন ডেলিগেট তৈরি করতে হবে এবং UIApplicationDelegateAdaptor অথবা NSApplicationDelegateAdaptor মাধ্যমে আপনার App স্ট্রাক্টের সাথে এটি সংযুক্ত করতে হবে। আপনাকে অ্যাপ ডেলিগেট সুইজলিংও অক্ষম করতে হবে। আরও তথ্যের জন্য, SwiftUI নির্দেশাবলী দেখুন।

    সুইফটইউআই

    @main
    struct YourApp: App {
      // register app delegate for Firebase setup
      @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
    
      var body: some Scene {
        WindowGroup {
          NavigationView {
            ContentView()
          }
        }
      }
    }
          

দূরবর্তী বিজ্ঞপ্তির জন্য নিবন্ধন করুন

হয় স্টার্টআপে, অথবা আপনার অ্যাপ্লিকেশন প্রবাহের কাঙ্ক্ষিত সময়ে, দূরবর্তী বিজ্ঞপ্তির জন্য আপনার অ্যাপটি নিবন্ধন করুন। দেখানো হিসাবে registerForRemoteNotifications এ কল করুন:

সুইফট

UNUserNotificationCenter.current().delegate = self

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
  options: authOptions,
  completionHandler: { _, _ in }
)

application.registerForRemoteNotifications()

অবজেক্টিভ-সি

[UNUserNotificationCenter currentNotificationCenter].delegate = self;
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
    UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter]
    requestAuthorizationWithOptions:authOptions
    completionHandler:^(BOOL granted, NSError * _Nullable error) {
      // ...
    }];

[application registerForRemoteNotifications];

ক্লায়েন্ট অ্যাপটিকে একটি বিষয়ে সাবস্ক্রাইব করুন

ক্লায়েন্ট অ্যাপগুলি যেকোনো বিদ্যমান বিষয়ে সাবস্ক্রাইব করতে পারে, অথবা তারা একটি নতুন বিষয় তৈরি করতে পারে। যখন একটি ক্লায়েন্ট অ্যাপ একটি নতুন বিষয়ের নামে সাবস্ক্রাইব করে (যা আপনার Firebase প্রকল্পের জন্য ইতিমধ্যে বিদ্যমান নেই), তখন FCM এ সেই নামের একটি নতুন বিষয় তৈরি করা হয় এবং যেকোনো ক্লায়েন্ট পরবর্তীতে এটিতে সাবস্ক্রাইব করতে পারে।

কোনও বিষয়ে সাবস্ক্রাইব করতে, আপনার অ্যাপ্লিকেশনের মূল থ্রেড থেকে সাবস্ক্রিপশন পদ্ধতিতে কল করুন ( FCM থ্রেড-নিরাপদ নয়)। যদি সাবস্ক্রিপশন অনুরোধ প্রাথমিকভাবে ব্যর্থ হয়, তাহলে FCM স্বয়ংক্রিয়ভাবে পুনরায় চেষ্টা করে। যেসব ক্ষেত্রে সাবস্ক্রিপশন সম্পন্ন করা সম্ভব হয় না, সেখানে সাবস্ক্রিপশন একটি ত্রুটি ফেলে যা আপনি একটি সমাপ্তি হ্যান্ডলারে দেখতে পাবেন যেমন দেখানো হয়েছে:

সুইফট

Messaging.messaging().subscribe(toTopic: "weather") { error in
  print("Subscribed to weather topic")
}

অবজেক্টিভ-সি

[[FIRMessaging messaging] subscribeToTopic:@"weather"
                                completion:^(NSError * _Nullable error) {
  NSLog(@"Subscribed to weather topic");
}];

এই কলটি FCM ব্যাকএন্ডে একটি অ্যাসিঙ্ক্রোনাস অনুরোধ করে এবং ক্লায়েন্টকে প্রদত্ত বিষয়ে সাবস্ক্রাইব করে। subscribeToTopic:topic কল করার আগে, নিশ্চিত করুন যে ক্লায়েন্ট অ্যাপ ইনস্ট্যান্সটি ইতিমধ্যেই কলব্যাক didReceiveRegistrationToken মাধ্যমে একটি নিবন্ধন টোকেন পেয়েছে।

প্রতিবার অ্যাপটি শুরু করার সময়, FCM নিশ্চিত করে যে সমস্ত অনুরোধ করা বিষয় সাবস্ক্রাইব করা হয়েছে। আনসাবস্ক্রাইব করতে, unsubscribeFromTopic:topic কল করুন, এবং FCM ব্যাকগ্রাউন্ডে টপিক থেকে আনসাবস্ক্রাইব করে।

বিষয়ভিত্তিক বার্তা গ্রহণ এবং পরিচালনা করা

FCM অন্যান্য ডাউনস্ট্রিম বার্তাগুলির মতোই বিষয়ভিত্তিক বার্তা সরবরাহ করে।

দেখানো পদ্ধতিতে application(_:didReceiveRemoteNotification:fetchCompletionHandler:) প্রয়োগ করুন:

সুইফট

@MainActor
func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable: Any]) async
  -> UIBackgroundFetchResult {
  // If you are receiving a notification message while your app is in the background,
  // this callback will not be fired till the user taps on the notification launching the application.
  // TODO: Handle data of notification

  // With swizzling disabled you must let Messaging know about the message, for Analytics
  // Messaging.messaging().appDidReceiveMessage(userInfo)

  // Print message ID.
  if let messageID = userInfo[gcmMessageIDKey] {
    print("Message ID: \(messageID)")
  }

  // Print full message.
  print(userInfo)
  print("Call exportDeliveryMetricsToBigQuery() from AppDelegate")
  Messaging.serviceExtension().exportDeliveryMetricsToBigQuery(withMessageInfo: userInfo)
  return UIBackgroundFetchResult.newData
}

অবজেক্টিভ-সি

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  // If you are receiving a notification message while your app is in the background,
  // this callback will not be fired till the user taps on the notification launching the application.
  // TODO: Handle data of notification

  // With swizzling disabled you must let Messaging know about the message, for Analytics
  // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];

  // ...

  // Print full message.
  NSLog(@"%@", userInfo);

  completionHandler(UIBackgroundFetchResultNewData);
}

পাঠানোর অনুরোধ তৈরি করুন

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

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

নোড.জেএস

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

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

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

জাভা

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

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

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

পাইথন

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

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

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

যাও

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

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

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

সি#

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

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

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

বিশ্রাম

POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
  "message":{
    "topic" : "foo-bar",
    "notification" : {
      "body" : "This is a Firebase Cloud Messaging Topic Message!",
      "title" : "FCM Message"
      }
   }
}

cURL কমান্ড:

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
  "message": {
    "topic" : "foo-bar",
    "notification": {
      "body": "This is a Firebase Cloud Messaging Topic Message!",
      "title": "FCM Message"
    }
  }
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

বিভিন্ন বিষয়ের সংমিশ্রণে বার্তা পাঠাতে, একটি শর্ত উল্লেখ করুন, যা একটি বুলিয়ান এক্সপ্রেশন যা লক্ষ্য বিষয়গুলি নির্দিষ্ট করে। উদাহরণস্বরূপ, নিম্নলিখিত শর্তটি TopicA এবং TopicB অথবা TopicC তে সাবস্ক্রাইব করা ডিভাইসগুলিতে বার্তা পাঠাবে:

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

FCM প্রথমে বন্ধনীতে যেকোনো শর্ত মূল্যায়ন করে, এবং তারপর বাম থেকে ডানে এক্সপ্রেশনটি মূল্যায়ন করে। উপরের এক্সপ্রেশনে, যে ব্যবহারকারী কোনও একক বিষয়ে সাবস্ক্রাইব করেছেন তিনি বার্তাটি পান না। একইভাবে, যে ব্যবহারকারী TopicA তে সাবস্ক্রাইব করেন না তিনি বার্তাটি পান না। এই সমন্বয়গুলি এটি গ্রহণ করে:

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

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

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

নোড.জেএস

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

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

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

জাভা

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

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

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

পাইথন

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

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

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

যাও

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

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

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

সি#

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

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

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

বিশ্রাম

POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
   "message":{
    "condition": "'dogs' in topics || 'cats' in topics",
    "notification" : {
      "body" : "This is a Firebase Cloud Messaging Topic Message!",
      "title" : "FCM Message",
    }
  }
}

cURL কমান্ড:

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "FCM Message",
    "body": "This is a Firebase Cloud Messaging Topic Message!",
  },
  "condition": "'dogs' in topics || 'cats' in topics"
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

পরবর্তী পদক্ষেপ