Skip to main content

PYMESSAGES - Google Messages Client for Python

What is this?

  • This is a Google Messages Client library to send message with a backend .eg. with flask 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. Ported from messages-web by Swapnil Soni.

How to use

  1. install the package from PyPI
pip install pymessages
  1. Use it
  • Without credentials
from pymessages.client import MessagesClient
import json
import base64
import re

client = MessagesClient()

@client.on('qr-code')
async def on_qr_code(base64Image):
    print("Generating qr code.")
    with open("qr.jpg", "wb") as f:
        f.write(base64.b64decode(re.sub(r'^data:image\/png;base64,','',base64Image)))

@client.on('authenticated')
async def on_authenticated(service):
    print("Authenticated")
    creds = await client.getCredentials()
    with open("credentials.json", 'w') as f:
        json.dump(creds, f, indent=4)

client.launch()
client.idle()

Then you can use credentials.json file to login .

  • With credentials
from pymessages.client import MessagesClient
import json

creds = MessagesClient.loadCredentialFile('credentials.json')
client = MessagesClient(creds)

@client.on('authenticated')
async def onAuthenticated(service):
    inbox = await service.getInbox(start=10, limit=20) #will return 20 elements starting from the 11th element. 
    # By default, start is 0 and limit is 50. You can set limit to -1 to return all elements after the starting point. 
    print(json.dumps(inbox, indent=4))

client.launch()
client.idle()
  1. send message
from pymessages.client import MessagesClient

creds = MessagesClient.loadCredentialFile('credentials.json')
client = MessagesClient(creds)

TO = "+919876543210"
MSG = "Test message sent using PyMessages wrapper."

@client.on('authenticated')
async def onAuthenticated(service):
    print("Sending Messages.")
    await service.sendMessage(TO, MSG)
    print("Done.")

client.launch()
client.idle()
  • 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
  • Use logger module

License

ISC - Swapnil Soni ©

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymessages-0.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymessages-0.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pymessages-0.2.tar.gz.

File metadata

  • Download URL: pymessages-0.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pymessages-0.2.tar.gz
Algorithm Hash digest
SHA256 bfca8174c65d707bd65f17b720f69844c57462a116aef1049e7cb9b8293c0688
MD5 d0ff4783bf72c1730ed81c3414f7abdb
BLAKE2b-256 ee9d1427ecf32392c36267b035451b86a41188c69e60b34b0f47beadda90581c

See more details on using hashes here.

File details

Details for the file pymessages-0.2-py3-none-any.whl.

File metadata

  • Download URL: pymessages-0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pymessages-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 61779d2b9a50f72cd055d34fbdd041d2ea3dcfaaead2663c66cece32acb62310
MD5 93a4cd1aef10b4f740c2df3efbda84f6
BLAKE2b-256 ea495cfa28ecd917afdc9a8db1ad329af3f0776006397620fc8370de3f9ca28c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page