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

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

How to Pass Data Variable into Twilio Text Body

问题

使用NodeJS服务器端,我有一个包含数据的变量,名为lowestPrice。我想要能够将这个变量的数据传递到发送的Twilio短信的正文中。

以下是我尝试的代码,但它不起作用。
这是否可能?如果可以,我该如何实现这个目标?

  1. const accountSid = 'abc123';
  2. const authToken = 'def456';
  3. const client = require('twilio')(accountSid, authToken);
  4. client.messages
  5. .create({
  6. body: '当前最低价格:' + $lowestPrice ,
  7. from: '+11234567890',
  8. to: '+10987654321'
  9. })
  10. .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?

  1. const accountSid = 'abc123';
  2. const authToken = 'def456';
  3. const client = require('twilio')(accountSid, authToken);
  4. client.messages
  5. .create({
  6. body: 'Current Lowest Price: ' + $lowestPrice ,
  7. from: '+11234567890',
  8. to: '+10987654321'
  9. })
  10. .then(message => console.log(message.sid));

Many Thanks!

答案1

得分: 0

使用JavaScript,你可以这样做:

  1. const accountSid = 'abc123';
  2. const authToken = 'def456';
  3. const client = require('twilio')(accountSid, authToken);
  4. let lowestPrice = 100;
  5. client.messages
  6. .create({
  7. body: `Current Lowest Price: ${lowestPrice}`,
  8. from: '+11234567890',
  9. to: '+10987654321'
  10. })
  11. .then(message => console.log(message.sid));

编辑 - 使用Node.js

  1. const { toPhoneNum, lowestPrice } = req.body;
  2. client.messages
  3. .create({
  4. body: lowestPrice,
  5. from: '+11234567890',
  6. to: toPhoneNum
  7. })
  8. .then(message => console.log(message.sid));

现在你可以在消息体中传递 Current Lowest Price: 100 消息。

英文:

with javascript you can do like this

  1. const accountSid = 'abc123';
  2. const authToken = 'def456';
  3. const client = require('twilio')(accountSid, authToken);
  4. let lowestPrice = 100;
  5. client.messages
  6. .create({
  7. body: `Current Lowest Price: ${lowestPrice}` ,
  8. from: '+11234567890',
  9. to: '+10987654321'
  10. })
  11. .then(message => console.log(message.sid));

EDIT - Using node.js

  1. const { toPhoneNum, lowestPrice} = req.body;
  2. client.messages
  3. .create({
  4. body: lowestPrice,
  5. from: '+11234567890',
  6. to: toPhoneNum
  7. })
  8. .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:

确定