Git Product home page Git Product logo

messages-web's Introduction

Google Messages Cli Client

What is this?

  • this is a Google Messages Client library to send message with a backend .eg. with express to send otp messages. This module uses your own number to work as a sms gateway api and you can send message to other person with your own number.

How to use

  1. install the package from npm
npm install messages-web
  1. Use it
  • Without credentials
const { default: MessagesClient } = require('messages-web')
const fs = require('fs')

const client = new MessagesClient()

client.on('qr-code', (base64Image) => {
    // example code to save image
    fs.writeFileSync('qr.jpg', base64Image.replace(/^data:image\/png;base64,/, ""), { encoding: 'base64' })
    // your code
})

client.on('authenticated', async (service) => {
    const inbox = service.getInbox()
    const credentials = await client.getCredentials()
    fs.writeFileSync('credentials.json', JSON.stringify(credentials, null, '\t'))
    await client.quit()
})

Then you can use credentials.json file to login

  • With credentials
const { default: MessagesClient } = require('messages-web')

const credentials = MessagesClient.loadCredentialFile('credentials.json')
const client = new MessagesClient({ credentials })

client.on('authenticated', async (service) => {
    const inbox = await service.getInbox()
    console.log('Inbox', inbox)
    await client.quit()
})
  1. send message
const { default: MessagesClient } = require('messages-web')

const credentials = MessagesClient.loadCredentialFile('credentials.json')
const client = new MessagesClient({ credentials })

client.on('authenticated', async (service) => {
    console.log('Sending message...')
    await service.sendMessage('+91987654321', 'Test message from SMS Client.') 
    console.log('Done!')
    await client.quit()
})

Note: sendMessage takes first arg as number with countryCode + Number second arg as TextMessage

  • Examples are given here.

Todos

  • add pagination in getInbox
  • add sendMessage in Service
  • add public method in client to save credentials to a file
  • sendMessage: parse to var to check if country code is included or not
  • Rewrite docs with proper details
  • detect if phone is not connected
  • detect if web client is open in another browser or not

License

ISC - Swapnil Soni ©

messages-web's People

Contributors

swapnilsoni1999 avatar shivamsn97 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.