简体   繁体   English

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

[英]How to publish to android via AWS Step Functions and AWS SNS

I am trying to push to Android phones via AWS Step Functions and AWS SNS.我正在尝试通过 AWS Step Functions 和 AWS SNS 推送到 Android 手机。

I am able to see the notification in the debug console, but it does not appear.我可以在调试控制台中看到通知,但没有出现。 How do i have to format the message correctly?我如何正确格式化消息? I tried several combinations, but none worked.我尝试了几种组合,但都没有奏效。

"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"
    }

The notification appears correctly on the phone if a send directly via SNS:如果直接通过 SNS 发送,通知会正确显示在手机上:

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

I also tried the Code Sample from the Step Functions Editor:我还尝试了 Step Functions Editor 中的代码示例:

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

When it comes to FCM Push Notifications, there are two types of message types that are supported ie “data” or ”notification”.对于 FCM 推送通知,支持两种类型的消息类型即“数据”或“通知”。

Looking at your message payload, I see you are using message of type "data" .查看您的消息有效负载,我看到您正在使用类型为"data" 的消息。 This means that:这意味着:

“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. “数据”消息不会由 FCM SDK 自动处理,也不会自动发送到通知中心,因此客户端需要处理此类消息。

Resolution:解析度:

You will need use message payload of type notification since you want the push notification to appear on the end-user device.您将需要使用通知类型的消息有效负载,因为您希望推送通知出现在最终用户设备上。 See sample state machine definition I authored:请参阅我编写的示例状态机定义:

{
"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
    }
  }
}

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM