英文:
How to Pass Data Variable into Twilio Text Body
问题
使用NodeJS服务器端,我有一个包含数据的变量,名为lowestPrice。我想要能够将这个变量的数据传递到发送的Twilio短信的正文中。
以下是我尝试的代码,但它不起作用。
这是否可能?如果可以,我该如何实现这个目标?
const accountSid = 'abc123';
const authToken = 'def456';
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
body: '当前最低价格:' + $lowestPrice ,
from: '+11234567890',
to: '+10987654321'
})
.then(message => console.log(message.sid));
非常感谢!
英文:
Using NodeJS server side, I have a variable with data in it called lowestPrice. I want to be able to pass this variable's data into the body of a Twilio text being sent.
Below is what I'm trying but it does not work.
Is this possible? If so, how do I accomplish this?
const accountSid = 'abc123';
const authToken = 'def456';
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
body: 'Current Lowest Price: ' + $lowestPrice ,
from: '+11234567890',
to: '+10987654321'
})
.then(message => console.log(message.sid));
Many Thanks!
答案1
得分: 0
使用JavaScript,你可以这样做:
const accountSid = 'abc123';
const authToken = 'def456';
const client = require('twilio')(accountSid, authToken);
let lowestPrice = 100;
client.messages
.create({
body: `Current Lowest Price: ${lowestPrice}`,
from: '+11234567890',
to: '+10987654321'
})
.then(message => console.log(message.sid));
编辑 - 使用Node.js
const { toPhoneNum, lowestPrice } = req.body;
client.messages
.create({
body: lowestPrice,
from: '+11234567890',
to: toPhoneNum
})
.then(message => console.log(message.sid));
现在你可以在消息体中传递 Current Lowest Price: 100
消息。
英文:
with javascript you can do like this
const accountSid = 'abc123';
const authToken = 'def456';
const client = require('twilio')(accountSid, authToken);
let lowestPrice = 100;
client.messages
.create({
body: `Current Lowest Price: ${lowestPrice}` ,
from: '+11234567890',
to: '+10987654321'
})
.then(message => console.log(message.sid));
EDIT - Using node.js
const { toPhoneNum, lowestPrice} = req.body;
client.messages
.create({
body: lowestPrice,
from: '+11234567890',
to: toPhoneNum
})
.then(message => console.log(message.sid));
Now you can pass the Current Lowest Price: 100
message in the body
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论