Giter Site home page Giter Site 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

j6k4m8 avatar paulomcnally avatar shivamsn97 avatar swapnilsoni1999 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

messages-web's Issues

QR code not scannable.

QR code saved was not scannable.
Then I edited the puppeteer to run with headless: false mode.

When I scan the QR code from chrome, error below shown.

C:\Users\Acer\Desktop\messages-web-main\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:208
this._callbacks.set(id, { resolve, reject, error: new Error(), method });
^

Error: Protocol error (Runtime.callFunctionOn): Target closed.
at C:\Users\Acer\Desktop\messages-web-main\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:208:63
at new Promise ()
at CDPSession.send (C:\Users\Acer\Desktop\messages-web-main\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:207:16)
at ExecutionContext._evaluateInternal (C:\Users\Acer\Desktop\messages-web-main\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:201:50)
at ExecutionContext.evaluateHandle (C:\Users\Acer\Desktop\messages-web-main\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:152:21)
at WaitTask.rerun (C:\Users\Acer\Desktop\messages-web-main\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:532:37)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

Can you help on this?

Errors when running examples on part SaveCredentials

Hello,
nor examples from readme.md nor from inside the code cannot get it working.

I am stuck on part Save credentials. It says, that the code doesn't exist. Nor const inbox = service.getInbox() getInbox exists.

Am I doing something wrong?

Include phone number in `getInbox` call

Right now we only list:

unread
id
timestamp
from
latestMsgText

but the from string is the contents of the sidebar title, not the actual from data. Ideally we have contact name and the actual phone number that can be directly plopped into sendMessage!

not can execute it

hello, I have installed it but I'm not sure what must do to can execute and try it because i got an error message

C:\Users\CHUCHIN\messages-web>node sendMessage.js
node:internal/modules/cjs/loader:1080
throw err;
^
issue

Error while installing

I'm getting following error, how can get rid of this. Any help on this would be great.

npm version ===> 6.14.16
node version ===>v12.22.12

npm install messages-web

[email protected] postinstall C:\PythonWebCode\latestbkup\verylatest\node_modules\puppeteer
node install.mjs

file:///C:/PythonWebCode/latestbkup/verylatest/node_modules/puppeteer/install.mjs:31
const {downloadBrowser} = await importInstaller();
^^^^^

SyntaxError: Unexpected reserved word
at Loader.moduleStrategy (internal/modules/esm/translators.js:140:18)
at async link (internal/modules/esm/module_job.js:42:21)

the qr is not scanning

the qr is just not scanning whenever i try from the qr.jpg file and scan it in my phone it doesnt fucking scan please help me before i get to your house

Timeout Error.

when I call the getInbox method than I will get this error most of the time.
imeoutError: waiting for selector body > mw-app > mw-bootstrap > div > main > mw-main-container > div > mw-main-nav > mws-conversations-list > nav > div.conv-container.ng-star-inserted > mws-conversation-list-item failed: timeout 30000ms exceeded.
is this error solvable somehow?

sendMessage fails with timeout error

Hey @SwapnilSoni1999! Let me know if this is too much repo traffic and I'll hold off on posting more :)

I'm seeing the same thing I think is the actual underlying issue in #6 from @admin1982, namely that the selector timeout fails.

When I inspect the browser where I've manually signed in, this selector does in fact resolve, but I'm not sure what the business logic is in the client that awaits this.

TimeoutError: waiting for selector `body > mw-app > mw-bootstrap > div > main > mw-main-container > div > mw-main-nav > mws-conversations-list > nav > div.conv-container.ng-star-inserted > mws-conversation-list-item` failed: timeout 30000ms exceeded
    at new WaitTask (###/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:509:34)
    at DOMWorld.waitForSelectorInPage (###/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:420:26)
    at Object.internalHandler.waitFor (###/node_modules/puppeteer/lib/cjs/puppeteer/common/QueryHandler.js:31:77)
    at DOMWorld.waitForSelector (###/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:313:29)
    at Frame.waitForSelector (###/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:841:51)
    at Page.waitForSelector (###/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:1280:33)
    at MessageService.<anonymous> (###/node_modules/messages-web/dist/lib/service.js:69:29)
    at Generator.next (<anonymous>)
    at fulfilled (###/node_modules/messages-web/dist/lib/service.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

send Message error caused by puppeteer disconnect browser before sending

C:\Users\v\Desktop\RN\gsms>node sendSms.js
Sending message...
retrying...
Message sent!
C:\Users\v\Desktop\RN\gsms\node_modules\puppeteer\lib\cjs\puppeteer\common\LifecycleWatcher.js:51
helper_js_1.helper.addEventListener(frameManager._client, Connection_js_1.CDPSessionEmittedEvents.Disconnected, () => this._terminate(new Error('Navigation failed because browser has disconnected!'))),
^

Error: Navigation failed because browser has disconnected!
at C:\Users\v\Desktop\RN\gsms\node_modules\puppeteer\lib\cjs\puppeteer\common\LifecycleWatcher.js:51:147
at C:\Users\v\Desktop\RN\gsms\node_modules\puppeteer\lib\cjs\vendor\mitt\src\index.js:51:62
at Array.map ()
at Object.emit (C:\Users\v\Desktop\RN\gsms\node_modules\puppeteer\lib\cjs\vendor\mitt\src\index.js:51:43)
at CDPSession.emit (C:\Users\v\Desktop\RN\gsms\node_modules\puppeteer\lib\cjs\puppeteer\common\EventEmitter.js:72:22)
at CDPSession._onClosed (C:\Users\v\Desktop\RN\gsms\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:247:14)
at Connection._onClose (C:\Users\v\Desktop\RN\gsms\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:128:21)
at WebSocket. (C:\Users\v\Desktop\RN\gsms\node_modules\puppeteer\lib\cjs\puppeteer\node\NodeWebSocketTransport.js:17:30)
at WebSocket.onClose (C:\Users\v\Desktop\RN\gsms\node_modules\ws\lib\event-target.js:136:16)
at WebSocket.emit (node:events:513:28)

Problem if headless true by default. nothing is happened

i have installed package "message-web" and then create new node.js project and put this

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

const client = new MessagesClient()

client.on('qr-code', (base64Image) => {
// example code to save image
console.log("Fdsfds");
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()
})

i have also created file "credentials.json" in root of project. and then if i run commaand "node message.js". as message.js is the file. nothing happend. can you please tell me where i get mistake?

DUBLICATE ISSUE: QR Code not scanning

Nothing happens when I scan the QR.jpg file with Google Messages App even when the QR refreshes nothing happens.

I am using the latest version of Google Messages App and It works with official Messages Web Website but I don't know why it doesn't work with this library. kek

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.