适用于NodeJS的AWS Pinpoint推送通知没有声音

当前,我有此参数可以准确地创建一条消息,

{
    applicationid: config.PROJECT_ID,MessageRequest: {
        Addresses: {
            [token]: {
                ChannelType: 'APNS'
            }
        },MessageConfiguration: {
            APNSMessage: {
                Title: notification.title,Body: notification.message
            }
        }
    }
}

我在https://docs.aws.amazon.com/pinpoint/latest/developerguide/send-messages-push.html处基于我的代码,我使用邮递员检查了它,并且在出现推送通知时没有声音,我注意到声音没有可用的参数,如何在通知中添加声音?>

在AWS Pinpoint测试消息系统中,我使用了此参数,该参数按预期工作,但是当我尝试使用上述代码并应用它时,它说"Unexpected key 'aps' found in params.MessageRequest.MessageConfiguration"

{
    APNSMessage: {
        aps: {
            alert: {
                title: notification.title,body: notification.message
            },sound: 'default'
        }
    }
}

我需要在NodeJS中使用aws-sdk添加默认值的声音

cyx194502 回答:适用于NodeJS的AWS Pinpoint推送通知没有声音

当使用标准消息发送推送通知时,Amazon Pinpoint SendMessages API不希望/不允许指定“ aps”字典。

  • 要使用标准消息发送带有声音的推送通知,请参考以下工作示例代码片段:

    // Specify the parameters to pass to the API.
    var params = {
      ApplicationId: '4fd13a40xxxxxxxx',MessageRequest: {
        Addresses: {
          ["token from APNS"]: {
            ChannelType: 'APNS'
          }
        },MessageConfiguration: {
            APNSMessage: {
            Title: 'TEST',Body: 'This is a sample push notification sent from Amazon Pinpoint by using Nodejs SDK',Sound: 'default',}
        }
      }
    };
    
  • 要使用“ aps”字典发送带有声音的推送通知,则需要使用:

(i)RawContent 属性:如果使用Pinpoint SDK / REST API /CLI。RawContent属性需要定义/指定为JSON格式的字符串,如下所示:

// Specify the parameters to pass to the API.
var params = {
  ApplicationId: '4fd13a40xxxxxxxx',MessageRequest: {
    Addresses: {
      "token from APNS": {
        ChannelType: 'APNS'
      }
    },MessageConfiguration: {
        APNSMessage: {
        RawContent : '{"aps":{"alert":"Hello,this is a test push notification!","sound":"default"}}' // If you define 'RawContent' here,everything ("message") else in the "MessageConfiguration" will be ignored.

      }
    }
  }
};

(ii)RawMessage 属性:如果使用如下所示的Pinpoint控制台:

{
    APNSMessage: {
        aps: {
            alert: {
                title: notification.title,body: notification.message
            },sound: 'default'
        }
    }
}

这说明了为什么在AWS Pinpoint控制台中进行测试并选择Test Messaging&Raw Message时,通知与声音一起正常工作。

本文链接:https://www.f2er.com/3116111.html

大家都在问