如何通过 AWS Step Functions 和 AWS SNS 发布到 android

How to publish to android via AWS Step Functions and AWS SNS

我正在尝试通过 AWS Step Functions 和 AWS SNS 推送到 Android phones。

我可以在调试控制台中看到通知,但它没有出现。我如何正确格式化消息?我尝试了几种组合,但 none 奏效了。

"Publish notification": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sns:publish",
      "Parameters": {
        "Message": {
          "default": "TestTestTest",
          "GCM": {
            "data": {
              "message": "Sample message for Android endpoints"
            }
          },
          "Input": "Hello from Step Functions!"
        },
        "MessageStructure": "json",
        "TargetArn": "arn:aws:sns:eu-central-1:xxxxxxxxx:endpoint/GCM/android/xxxxxxxxxxxxx"
      },
      "Next": "next state"
    }

如果直接通过 SNS 发送,通知会在 phone 上正确显示:

"GCM": "{ \"data\": { \"message\": \"Sample message for Android endpoints\" } }"

我还尝试了 Step Functions 编辑器中的代码示例:

"Message": {
  "Input": "Hello from Step Functions!"
}

对于 FCM 推送通知,支持两种类型的 message types ,即“数据”或“通知”。

查看您的消息负载,我发现您使用的消息类型为 "data"。这意味着:

“data" messages are not automatically handled by the FCM SDKs and will not be delivered to the notification center automatically therefore the clients' need to handle this type of messages.

解析:

您需要使用类型为 notification 的消息负载,因为您希望推送通知出现在最终用户设备上。请参阅我编写的示例状态机定义:

{
"StartAt": "Publish to SNS",
"States": {
  "Publish to SNS": {
    "Type": "Task",
    "Resource": "arn:aws:states:::sns:publish",
    "Parameters": {
      "TargetArn": "arn:aws:sns:us-east-1:xxxxxxx:endpoint/GCM/AWSNS-Android/xxxxx-xxxxxxx-xxxxxxx",
      "MessageStructure": "json",
      "Message": {"GCM": "{ \"notification\": { \"body\": \"sample test push\" } }"}
    },
    "End": true
    }
  }
}

希望对您有所帮助!