const res = await client.verify
.v2
.services(twilioConfig.verifySid)
.verifications.create({
channelConfiguration: {
template_id: templates.accountLinkingVerificationEmail,
from: process.env.SENDGRID_FROM_EMAIL,
dynamic_template_data: {
primary_name: primaryName,
secondary_name: secondaryName,
},
},
to: childEmail,
channel: 'email',
})
.then((verification) => console.log(verification.sid));
我正在尝试发送动态内容来填充我的 SendGrid 动态模板。我在 {{twilio_code}} 变量中收到 Twilio 验证码。但是,当我尝试使用其他动态值(例如 {{primary_name}} 和 {{secondary_name}})时,它们不会出现在电子邮件中;它们显示为空字符串。有人可以帮我解决这个问题吗?预先感谢。
dynamic_template_data
不支持参数channelConfiguration
。但您可以使用 substitutions
参数来覆盖动态模板中找到的文本。
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);
async function createVerification() {
const verification = await client.verify.v2
.services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
.verifications.create({
channel: "email",
channelConfiguration: {
substitutions: {
username: "Foo Bar",
},
},
to: "[email protected]",
});
console.log(verification.sid);
}
createVerification();
PS:该用户提出了类似的问题,可能会提供更多背景信息。