[Firebase] 주제로 메시지 보내기 python

최준혁·2023년 12월 6일
0
post-thumbnail

순서

  1. 주제 구독 fcmtoken사용
  2. 선택한 주제(그룹)로 발송

공식문서: https://firebase.google.com/docs/cloud-messaging/android/topic-messaging?hl=ko

  • How I wrote

      def send_push_topic(title, body, topic, post_id, push_id, url, badge_count):
    
           apns_options = messaging.APNSConfig(
               payload=messaging.APNSPayload(
                   aps=messaging.Aps(
                       alert=messaging.ApsAlert(title=title, body=body),
                       badge=badge_count,  # Set the badge count here
                       # sound="default",  # Set the notification sound
                       # category="<your-category>",  # Optional: Set the notification category
                   ),
               ),
           )
           # Define Android-specific parameters
           android_config = messaging.AndroidConfig(
               notification=messaging.AndroidNotification(
                   title=title,
                   body=body,
                   icon='ico_noti', # depands on ur choice
                   color='#2c6ceb', # depands on ur choice
                   # notification_count=badge_count,
                   # click_action="<your-action>",  # Optional: Set the action when the notification is clicked
               ),
               priority="high",  # Set the priority of the notification
           )
    
           message = messaging.Message(
               apns=apns_options,
               android=android_config,
               data={'title': title, 'text': body, 'post_id': post_id, 'push_id': push_id, 'url': url, 'badge': "1"},
               topic=topic, # eg) "'stock-GOOG' in topics || 'industry-tech' in topics"
           )
           res = messaging.send(message)
           print('Successfully sent message:', res)
profile
I LOVE MONDAY

0개의 댓글