0.1.6 • Published 3 years ago

textnow.js v0.1.6

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

TextNow API

textnow.js is a node.js module that uses TextNow to enable free programmable texting

Credit

  • Developer: Leonardo Wu-Gomez
  • Reddit: leogomezz4t
  • Please tell me if you have any ideas for the API or reporting a bug

Installation

Method One: Using git clone

git clone https://github.com/leogomezz4t/textnow.js.git

Method Two: Using npm

npm install textnow.js --save

Usage

Ways to authenticate

const tn = require("textnow.js")

// Way 1. Just instantiate and a prompt will appear on the command line
const client = new tn.Client("email")
// Way 3. If you inputed the wrong cookie and are getting failed requests. This is how to reset it
client.auth_reset()
// will redo the prompt

How to send an sms message

(async () => {
await client.sendSMS("number", "Hello World!")
})

How to get new messages

const newMessages = await client.getUnreadMessages() -> Array
for (const message of newMessages):
    await message.markAsRead()
    console.log(message)
    // Message object
    // content: "body of sms"
    // number: "number of sender"
    // date: datetime object of when the message was received
    // read: bool
    // id: int
    // direction: SENT_MESSAGE_TYPE or RECEIVED_MESSAGE_TYPE
    // first_contact: bool if its the first time that number texted you
    // type: MESSAGE_TYPE if type is Message and MULTIMEDIAMESSAGE_TYPE if type is MultiMediaMessage

    // Functions
    // async markAsRead() will post the server as read
    // async sendSMS() will send an sms to the number who sent the message
    
    // MultiMediaMessage object
    // All the attributes of Message
    // content: url of media
    // rawData: bytes of the media
    // contentType: str the MIME type ie. "image/jpeg" or "video/mp4"
    // extension: str of the file extension is. "jpeg" or "mp4"
    // Functions
    // mv(file_path): downloads the file to file_path

    console.log(message.number)
    console.log(message.content)

    // MultiMediaMessage

    console.log(message.content_type)
    message.mv("./image." + message.extension)

How to get all messages

const messages = await client.getMessages() -> Array
// Same as above

How to get all sent messages

const sentMessages = await client.getSentMessages() -> Array
// same as above

Simple bot snippet

const tn = require("textnow.js")

(async () => {
    const client = new tn.Client("email")
    client.on("message", msg => {
        if (msg.content === "ping") {
            await client.sendSMS(msg.number, "pong")
        }
    })
})()

Patch Notes

0.1.4

  • Bug fix

0.1.3

  • Bug fix

0.1.2

  • Bug fix

0.1.1

  • Bug Fix

0.1.0

  • Initial Commit
  • Can send messages
  • Can recieve messages
  • can mark message as read

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago