如何将数据变量传递到Twilio短信正文中

huangapple go评论79阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月28日 12:15:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349912.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定