NodeJS es模块中的Twilio节点

umuewwlo  于 2023-02-15  发布在  Node.js
关注(0)|答案(2)|浏览(125)

如何将twilio导入节点模块?

const client = require("twilio")(YOUR_ACCOUNT_SID, YOUR_AUTH_TOKEN);
xmjla07d

xmjla07d1#

在库中(您可以看到here):

module.exports = function(accountSid, authToken, opts) {
    return new Twilio(accountSid, authToken, opts);
}

module.exports = Car将等效于export default Car
因此,您可以使用以下命令导入模块:

import twilio from "twilio";
//     ^ this will select default export

const client = twilio(YOUR_ACCOUNT_SID, YOUR_AUTH_TOKEN);
v8wbuo2f

v8wbuo2f2#

您可以执行以下操作:

import * as Twilio from 'twilio';

const YOUR_AUTH_TOKEN = process.env.TWILIO_AUTH_TOKEN;
const YOUR_ACCOUNT_SID = process.env.TWILIO_ACCOUNT_SID;

const client = Twilio(YOUR_ACCOUNT_SID, YOUR_AUTH_TOKEN);

client.messages
  .create({
     body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
     from: '+15017122661',
     to: '+15558675310'
   })
  .then(message => console.log(message.sid));

确保正确安装twilio

相关问题