是否可以在 Amazon Pinpoint 模板中添加一组对象作为替换值?

问题描述

我正在尝试向 Amazon Pinpoint 提交 API 请求(通过 AWS Lambda 中的 AWS JavaScript 开发工具包)以触发模板化电子邮件。这个想法是 Lambda 接收一个事件,解析数据,然后将 API 请求提交给 Amazon Pinpoint 的 API。我希望模板为对象数组中的模板提供替换值,但我找不到 Amazon Pinpoint 解析这种类型结构的方法,即使 it is supported by Handlebars.js(Amazon Pinpoint 模板是建立在其之上的)。

Amazon Pinpoint's documentation 注意到 Substitution 值必须是一个字符串数组,但是 Amazon SES's templating works with a stringified objects/arrays:

有没有办法让 Amazon Pinpoint / Handlebars.js 从替换数组中解析字符串化对象?原始事件具有以下结构:

{
    "errors": [{
        "id": "b174e31c-9d10-4654-92ae-78fc5ea5ffb0","dateTime": "2021-03-30 10:30:34"
      },{
        "id": "bbb6aac1-ca6a-45e7-a8dd-7258bce1ed8b","dateTime": "2021-03-30 11:00:35"
      }
    ]
}

我希望能够解析以下 HTML 模板中的每个对象(使用 Handlebars.js syntax):

<!DOCTYPE html>
<html>
<head>
<title>Internal Warning</title>
</head>
<body>

<p>The system generated the following warnings:</p>

<ul>
    {{#each errors}}
    <li>Error ID: {{this.id}} </li>
    <li>Error Datetime: {{this.dateTime}} </li>
    {{/each}}
</ul>

<p>Please test the appropriate system and address any issues.</p>

</body>
</html>

我试过了:

  1. 将对象数组插入 Substitutions 映射中的 Addresses 属性,这会返回验证/类型错误:“InvalidParameterType: Expected params.MessageRequest.Addresses['test123@dispostable.com'] .Substitutions['errors'][0] 为字符串"
  2. 在将每个对象插入到同一属性之前对其进行字符串化,这会阻止 Handlebars.js 对其进行正确解析。

非常感谢任何帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)