簡體   English   中英

如何通過 AWS SNS 發送高優先級推送通知

[英]How to send the High priority push notification through AWS SNS

我們需要使用 Amazon SNS 服務將高優先級推送通知發送到手機 android。

我們能夠發送正常的優先級消息,但我們不能在消息中包含優先級屬性。

謝謝

它的記錄很少,但這是它的工作原理。

確保幾件事情到位:

  1. 您的 SNS 客戶端使用 MessageStructure='json' 屬性發布消息
  2. 您在 SNS 負載中有消息的“默認”版本
  3. 您將自定義有效負載鍵中的任何內容序列化為字符串。

Python 示例如下所示

sns: SNSClient = boto3.client('sns', region_name='us-east-1')
message = json.dumps(
    {
        "default": json.dumps(
            {
                "priority": "high",
                "data": {"my": "custom", "payload": "here"},
                "notification": {
                    "title": "Ukraine is awesome",
                    "body": "Ukraine is awesome",
                },
            }
        ),
        "GCM": json.dumps(
            {
                "priority": "high",
                "data": {"my": "custom", "payload": "here"},
                "notification": {
                    "title": "Ukraine is awesome",
                    "body": "Ukraine is awesome",
                },
            }
        ),
    }
)

response = sns.publish(
    TopicArn=SNS_TOPIC,
    Message=message,
    MessageStructure='json',
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM