Node.js NodeJS的AWS精确定位推送通知没有声音

Node.js NodeJS的AWS精确定位推送通知没有声音,node.js,amazon-web-services,aws-sdk,aws-sdk-js,aws-pinpoint,Node.js,Amazon Web Services,Aws Sdk,Aws Sdk Js,Aws Pinpoint,目前,我使用此参数在pinpoint中创建消息 { ApplicationId: config.PROJECT_ID, MessageRequest: { Addresses: { [token]: { ChannelType: 'APNS' } }, MessageConfiguration: { APNSMessage: {

目前,我使用此参数在pinpoint中创建消息

{
    ApplicationId: config.PROJECT_ID,
    MessageRequest: {
        Addresses: {
            [token]: {
                ChannelType: 'APNS'
            }
        },
        MessageConfiguration: {
            APNSMessage: {
                Title: notification.title,
                Body: notification.message
            }
        }
    }
}
我把我的代码放在这里,我用邮递员检查了一下,当推送通知出现时没有声音,我注意到没有声音参数,我怎么能在通知中添加声音

在AWS Pinpoint Test Messaging中,我使用了这个参数,它工作正常,但当我使用上述代码尝试并应用它时,它说
“在params.MessageRequest.MessageConfiguration中找到了意外的键'aps'”

我需要在NodeJS中使用aws sdk添加一个默认值的声音,Amazon Pinpoint 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.

      }
    }
  }
};
{
    APNSMessage: {
        aps: {
            alert: {
                title: notification.title,
                body: notification.message
            },
            sound: 'default'
        }
    }
}
(ii)RawMessage属性:如果使用Pinpoint控制台,如下图所示:

// 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.

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

这解释了为什么当您在AWS Pinpoint console中进行测试并选择测试消息和原始消息时,通知与声音正常工作。

我已经完成了此实现,顺便说一句,感谢您的回答。看起来和我做的一样:)