twilio / twilio-node

Node.js helper library
MIT License
1.4k stars 511 forks source link

ES6 support #696

Closed Prasundas99 closed 3 years ago

Prasundas99 commented 3 years ago

In documentation the code to integrate with node js is as follows:

`var accountSid = process.env.TWILIO_ACCOUNT_SID; // Your Account SID from www.twilio.com/console var authToken = process.env.TWILIO_AUTH_TOKEN; // Your Auth Token from www.twilio.com/console

const client = require('twilio')(accountSid, authToken, { lazyLoading: true });`

but I am using type:module in my node js application which means I have to import them

So how should I import the twillio module

shwetha-manvinkurke commented 3 years ago

Try import { Twilio } from "twilio"?

Prasundas99 commented 3 years ago

Thank You the issue has been solved here is the code if someone needs it in future

import twilio from 'twilio';

export const twillosms = async (number, authCode) => {

  const accountSid = process.env.TWILIO_ACCOUNT_SID;
  const authToken = process.env.TWILIO_AUTH_TOKEN;

  const client = new twilio(accountSid, authToken);
  await client.messages
    .create({
      to: `${number}`,
      from: '${twillonumber}',
      body: ``,
    })
    .then(message => console.log(message))
    .catch((err) => console.log(err))

}